diff --git a/pom.xml b/pom.xml index b9a64dd6..b619a639 100644 --- a/pom.xml +++ b/pom.xml @@ -56,6 +56,12 @@ + + + ws.schild + jave-all-deps + 2.5.1 + org.springframework.boot spring-boot-starter-webflux diff --git a/src/main/java/com/peanut/modules/master/controller/CourseController.java b/src/main/java/com/peanut/modules/master/controller/CourseController.java index ec355fe3..62eb25b5 100644 --- a/src/main/java/com/peanut/modules/master/controller/CourseController.java +++ b/src/main/java/com/peanut/modules/master/controller/CourseController.java @@ -16,10 +16,13 @@ import com.peanut.modules.master.service.*; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import ws.schild.jave.MultimediaObject; +import java.net.URL; import java.util.List; import java.util.Map; @@ -215,6 +218,11 @@ CourseController { @RequestMapping("/addCourseCatalogueChapterVideo") public R addCourseCatalogueChapterVideo(@RequestBody CourseCatalogueChapterVideoEntity courseCatalogueChapterVideoEntity){ boolean save = courseCatalogueChapterVideoService.save(courseCatalogueChapterVideoEntity); + if (courseCatalogueChapterVideoEntity.getType()==2){ + int duration = getMP3Duration(courseCatalogueChapterVideoEntity); + courseCatalogueChapterVideoEntity.setDuration(duration); + courseCatalogueChapterVideoService.updateById(courseCatalogueChapterVideoEntity); + } return save?R.ok():R.error("error"); } @@ -264,6 +272,11 @@ CourseController { @RequestMapping("/editCourseCatalogueChapterVideo") public R editCourseCatalogueChapterVideo(@RequestBody CourseCatalogueChapterVideoEntity courseCatalogueChapterVideoEntity){ courseCatalogueChapterVideoService.updateById(courseCatalogueChapterVideoEntity); + if (courseCatalogueChapterVideoEntity.getType()==2){ + int duration = getMP3Duration(courseCatalogueChapterVideoEntity); + courseCatalogueChapterVideoEntity.setDuration(duration); + courseCatalogueChapterVideoService.updateById(courseCatalogueChapterVideoEntity); + } return R.ok(); } @@ -279,6 +292,25 @@ CourseController { return R.ok().put("shopProductListhopProducts",shopProductListhopProducts); } - + //获取音频时长 + public int getMP3Duration(CourseCatalogueChapterVideoEntity video){ + try{ + String s_str = ""; + if (video.getVideo().startsWith("article/")) { + s_str = "http://oss.taihumed.com/voice/article/"; + }else if (video.getVideo().startsWith("mingyijingcai/")) { + s_str = "http://oss.taihumed.com/voice/"; + }else { + s_str = "http://oss.taihumed.com/voice/taiHuClass/"; + } + URL url = new URL(s_str+video.getVideo()); + MultimediaObject multimediaObject = new MultimediaObject(url); + long duration = (multimediaObject.getInfo().getDuration())/1000; + return Integer.parseInt(duration+""); + }catch (Exception e){ + e.printStackTrace(); + } + return 0; + } }