Просмотр исходного кода

feat(video): 添加视频时计算并保存视频时长

- 在LifeUserLearningVideoService接口中添加IOException和InterruptedException异常声明
- 引入VideoDurationFFmpeg工具类用于获取视频时长
- 在新增学习视频方法中调用FFmpeg获取视频时长并保存到实体中
- 将计算出的视频时长设置到LifeUserLearningVideo对象的videoDuration字段
fcw 3 месяцев назад
Родитель
Сommit
f4034a8162

+ 3 - 1
alien-store/src/main/java/shop/alien/store/service/LifeUserLearningVideoService.java

@@ -5,12 +5,14 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import shop.alien.entity.result.R;
 import shop.alien.entity.store.LifeUserLearningVideo;
 
+import java.io.IOException;
+
 public interface LifeUserLearningVideoService extends IService<LifeUserLearningVideo> {
 
     /**
      * 新增学习视频
      */
-    R<String> add(LifeUserLearningVideo lifeUserLearningVideo);
+    R<String> add(LifeUserLearningVideo lifeUserLearningVideo) throws IOException, InterruptedException;
 
     /**
      * 根据ID删除学习视频

+ 6 - 1
alien-store/src/main/java/shop/alien/store/service/impl/LifeUserLearningVideoServiceImpl.java

@@ -12,6 +12,9 @@ import shop.alien.entity.result.R;
 import shop.alien.entity.store.LifeUserLearningVideo;
 import shop.alien.mapper.LifeUserLearningVideoMapper;
 import shop.alien.store.service.LifeUserLearningVideoService;
+import shop.alien.util.common.VideoDurationFFmpeg;
+
+import java.io.IOException;
 
 @Service
 @RequiredArgsConstructor
@@ -19,8 +22,10 @@ import shop.alien.store.service.LifeUserLearningVideoService;
 public class LifeUserLearningVideoServiceImpl extends ServiceImpl<LifeUserLearningVideoMapper, LifeUserLearningVideo> implements LifeUserLearningVideoService {
 
     @Override
-    public R<String> add(LifeUserLearningVideo lifeUserLearningVideo) {
+    public R<String> add(LifeUserLearningVideo lifeUserLearningVideo) throws IOException, InterruptedException {
         log.info("LifeUserLearningVideoServiceImpl.add, param={}", lifeUserLearningVideo);
+        long videoDuration = VideoDurationFFmpeg.getVideoDuration(lifeUserLearningVideo.getVideoUrl());
+        lifeUserLearningVideo.setVideoDuration(String.valueOf(videoDuration));
         boolean result = this.save(lifeUserLearningVideo);
         if (result) {
             return R.success("新增成功");