时长信息转到video主体 增加多线程获取时间方法
This commit is contained in:
30
src/main/java/com/peanut/common/service/AsyncService.java
Normal file
30
src/main/java/com/peanut/common/service/AsyncService.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package com.peanut.common.service;
|
||||
|
||||
import com.aliyun.vod20170321.models.GetVideoPlayAuthResponse;
|
||||
import com.peanut.common.utils.SpdbUtil;
|
||||
import com.peanut.modules.common.dao.CourseCatalogueChapterVideoDao;
|
||||
import com.peanut.modules.common.entity.CourseCatalogueChapterVideoEntity;
|
||||
import com.peanut.modules.common.entity.UserCourseVideoPositionEntity;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class AsyncService {
|
||||
@Autowired
|
||||
private CourseCatalogueChapterVideoDao courseCatalogueChapterVideoDao;
|
||||
|
||||
@Async
|
||||
public void pushDurationToVideo(Integer videoId) throws Exception {
|
||||
CourseCatalogueChapterVideoEntity courseCatalogueChapterVideoEntity = courseCatalogueChapterVideoDao.selectById(videoId);
|
||||
if(courseCatalogueChapterVideoEntity.getType()==1){
|
||||
GetVideoPlayAuthResponse p = SpdbUtil.getPlayAuth(courseCatalogueChapterVideoEntity.getVideo());
|
||||
int i = p.getBody().getVideoMeta().getDuration().intValue();
|
||||
courseCatalogueChapterVideoEntity.setDuration(i);
|
||||
}else{
|
||||
Integer mp4Duration = SpdbUtil.getMp4Duration("https://ehh-private-01.oss-cn-beijing.aliyuncs.com/video/taiHuClass/" + courseCatalogueChapterVideoEntity.getVideo());
|
||||
courseCatalogueChapterVideoEntity.setDuration(mp4Duration);
|
||||
}
|
||||
courseCatalogueChapterVideoDao.updateById(courseCatalogueChapterVideoEntity);
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,25 @@ import com.aliyun.teautil.models.RuntimeOptions;
|
||||
import com.aliyun.vod20170321.Client;
|
||||
import com.aliyun.vod20170321.models.GetVideoPlayAuthRequest;
|
||||
import com.aliyun.vod20170321.models.GetVideoPlayAuthResponse;
|
||||
import org.bytedeco.javacv.FFmpegFrameGrabber;
|
||||
import org.bytedeco.javacv.FrameGrabber;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class SpdbUtil {
|
||||
|
||||
public static Integer getMp4Duration(String url){
|
||||
double duration = 0;
|
||||
try (FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(url)) {
|
||||
frameGrabber.start();
|
||||
duration = frameGrabber.getLengthInTime()/1000000;
|
||||
frameGrabber.stop();
|
||||
} catch (FrameGrabber.Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return (int)duration;
|
||||
};
|
||||
|
||||
public static GetVideoPlayAuthResponse getPlayAuth(String vid) throws Exception {
|
||||
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
||||
|
||||
Reference in New Issue
Block a user