Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
wyszyk
Project
Project
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
Graph
比较
统计图
议题
0
议题
0
列表
看板
标记
Milestones
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
注册表
注册表
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
任建彩
wyszyk
Commits
f1f47881
提交
f1f47881
authored
5月 09, 2023
作者:
任建彩
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat:打包文件名
1.file
上级
bacd7914
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
101 行增加
和
18 行删除
+101
-18
pom.xml
wyszyk-provider/wyszyk-provider-file/pom.xml
+4
-4
FileController.java
...java/com/zrqx/file/controller/backend/FileController.java
+3
-12
VideoTimeUtil.java
...-file/src/main/java/com/zrqx/file/util/VideoTimeUtil.java
+92
-0
pom.xml
wyszyk-provider/wyszyk-provider-third/pom.xml
+2
-2
没有找到文件。
wyszyk-provider/wyszyk-provider-file/pom.xml
浏览文件 @
f1f47881
...
...
@@ -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>
...
...
wyszyk-provider/wyszyk-provider-file/src/main/java/com/zrqx/file/controller/backend/FileController.java
浏览文件 @
f1f47881
...
...
@@ -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
(
"无法获取视频时长!"
);
}
...
...
wyszyk-provider/wyszyk-provider-file/src/main/java/com/zrqx/file/util/VideoTimeUtil.java
0 → 100644
浏览文件 @
f1f47881
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
()));
}
}
wyszyk-provider/wyszyk-provider-third/pom.xml
浏览文件 @
f1f47881
...
...
@@ -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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论