提交 f1f47881 authored 作者: 任建彩's avatar 任建彩

feat:打包文件名

1.file
上级 bacd7914
......@@ -17,11 +17,11 @@
</properties>
<dependencies>
<!--视频时长 -->
<!-- 读取视频时长 -->
<dependency>
<groupId>it.sauronsoftware.jave</groupId>
<artifactId>jave</artifactId>
<version>1.0.2</version>
<groupId>ws.schild</groupId>
<artifactId>jave-core</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
......
......@@ -12,6 +12,7 @@ import com.zrqx.file.model.form.CreatreQRCodeForm;
import com.zrqx.file.model.form.FileDownloadForm;
import com.zrqx.file.model.po.FileInfo;
import com.zrqx.file.service.FileService;
import com.zrqx.file.util.VideoTimeUtil;
import com.zrqx.provider.feign.resource.ResourceClient;
import com.zrqx.util.DownloadUtil;
import com.zrqx.util.ZipUtil;
......@@ -19,8 +20,6 @@ import com.zrqx.util.datatype.UUIDUtil;
import com.zrqx.util.redis.Redis;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.MultimediaInfo;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
......@@ -176,13 +175,9 @@ public class FileController {
FileInfo entity = service.uploadFile(file);
if (entity.getContentType().toLowerCase().contains("video") || entity.getContentType().toLowerCase().contains("audio")) {
File newfile = new File(rootPath + entity.getPath() + "/" + entity.getFileName() + entity.getSuffixName());
Encoder encoder = new Encoder();
// String videotime = "0分0秒";
try {
MultimediaInfo mInfo = encoder.getInfo(newfile);
long ls = mInfo.getDuration();
long ls = VideoTimeUtil.getVideoDuration(newfile);
entity.setTime(ls);
// videotime = ls / 60000 + "分" + (ls / 1000) % 60 + "秒";
} catch (Exception e) {
throw new FileBizException("无法获取视频时长!");
}
......@@ -199,13 +194,9 @@ public class FileController {
public FileInfo uploadVideo(String code,@RequestParam("file") MultipartFile file, HttpServletRequest request) throws Exception {
FileInfo entity = service.uploadFile(file);
File newfile = new File(rootPath + entity.getPath() + "/" + entity.getFileName() + entity.getSuffixName());
Encoder encoder = new Encoder();
// String videotime = "0分0秒";
try {
MultimediaInfo mInfo = encoder.getInfo(newfile);
long ls = mInfo.getDuration();
long ls = VideoTimeUtil.getVideoDuration(newfile);
entity.setTime(ls);
// videotime = ls / 60000 + "分" + (ls / 1000) % 60 + "秒";
} catch (Exception e) {
throw new FileBizException("无法获取视频时长!");
}
......
package com.zrqx.file.util;
import com.google.common.collect.ImmutableList;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
import org.springframework.web.multipart.MultipartFile;
import ws.schild.jave.MultimediaObject;
import ws.schild.jave.info.MultimediaInfo;
import java.io.File;
@Slf4j
public class VideoTimeUtil {
private static ImmutableList<String> videoSuffixList = ImmutableList.of("mp4", "mov", "avi", "mkv", "m4v", "wmv",
"asf", "asx", "rm", "rmvb", "3gp", "dat", "flv", "vob");
/**
* 视频时长
*
* @param file
* @return String[] 0=秒时长,1=展示时长(格式如 01:00:00)
*/
public static String[] parseDuration(File file) {
String[] length = new String[2];
try {
//
// URL source = new URL(fileUrl);
// 构造方法 接受URL对象
// MultimediaObject instance = new MultimediaObject(source);
// 构造方法 接受File对象
MultimediaObject instance = new MultimediaObject(file);
MultimediaInfo result = instance.getInfo();
Long ls = result.getDuration() / 1000;
length[0] = String.valueOf(ls);
Integer hour = (int) (ls / 3600);
Integer minute = (int) (ls % 3600) / 60;
Integer second = (int) (ls - hour * 3600 - minute * 60);
String hr = hour.toString();
String mi = minute.toString();
String se = second.toString();
if (hr.length() < 2) {
hr = "0" + hr;
}
if (mi.length() < 2) {
mi = "0" + mi;
}
if (se.length() < 2) {
se = "0" + se;
}
String noHour = "00";
if (noHour.equals(hr)) {
length[1] = mi + ":" + se;
} else {
length[1] = hr + ":" + mi + ":" + se;
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return length;
}
/**
* 获取视频时长 * @param file 视频文件
* @return 时长(秒)
*/ public static long getVideoDuration(File file){
long duration = 0;
File tempFile = null;
try{
// tempFile = File.createTempFile(UUIDUtil.uuid(), "." + FilenameUtils.getExtension(file.getOriginalFilename()));
// file.transferTo(tempFile);
MultimediaObject multimediaObject = new MultimediaObject(file);
MultimediaInfo info = multimediaObject.getInfo();
duration = info.getDuration() / 1000;
} catch (Exception e){
log.error("获取视频时长失败", e);
} finally {
if (tempFile != null){
tempFile.delete();
}
}
return duration;
}
/**
* 判断文件是否是视频 * @param file 文件
* @return 是否是啊视频
*/ public static boolean isVideo(MultipartFile file){
return videoSuffixList.contains(FilenameUtils.getExtension(file.getOriginalFilename()));
}
}
......@@ -51,10 +51,10 @@
</dependencies>
<build>
<plugins>
<plugin>
<!-- <plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugin>-->
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论