上传音频时设置音频时长
This commit is contained in:
6
pom.xml
6
pom.xml
@@ -56,6 +56,12 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!--获取音频时长-->
|
||||
<dependency>
|
||||
<groupId>ws.schild</groupId>
|
||||
<artifactId>jave-all-deps</artifactId>
|
||||
<version>2.5.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user