Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
1fddc0e2
Commit
1fddc0e2
authored
Nov 12, 2021
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改实例化关系
parent
11c2dcd0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
5 deletions
+49
-5
MediaCacheLocal.java
.../src/main/java/com/yanzuoguang/media/MediaCacheLocal.java
+36
-0
MediaFirst.java
...image/src/main/java/com/yanzuoguang/media/MediaFirst.java
+13
-5
No files found.
yzg-util-image/src/main/java/com/yanzuoguang/media/MediaCacheLocal.java
View file @
1fddc0e2
package
com
.
yanzuoguang
.
media
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 本地缓存实现
*
* @author 颜佐光
*/
public
class
MediaCacheLocal
implements
MediaCacheBase
{
private
Map
<
String
,
MapLock
>
mapLock
=
new
HashMap
<
String
,
MapLock
>();
/**
* 获取缓存是否正在执行
*
...
...
@@ -38,4 +44,34 @@ public class MediaCacheLocal implements MediaCacheBase {
public
void
sub
(
MediaResVo
res
)
{
}
/**
* 锁定临时文件,防止被人修改
*
* @param req
* @param runnable
*/
@Override
public
void
lockTempFile
(
MediaReqVo
req
,
Runnable
runnable
)
{
MapLock
lock
=
getMapLock
(
req
);
synchronized
(
lock
.
lockTemp
)
{
runnable
.
run
();
}
}
private
MapLock
getMapLock
(
MediaReqVo
req
)
{
synchronized
(
mapLock
)
{
MapLock
lock
=
this
.
mapLock
.
get
(
req
.
getUrl
());
if
(
lock
==
null
)
{
lock
=
new
MapLock
();
this
.
mapLock
.
put
(
req
.
getUrl
(),
lock
);
}
return
lock
;
}
}
private
static
class
MapLock
{
Object
lockTemp
=
new
Object
();
MediaResVo
res
;
}
}
yzg-util-image/src/main/java/com/yanzuoguang/media/MediaFirst.java
View file @
1fddc0e2
...
...
@@ -9,6 +9,11 @@ import org.springframework.stereotype.Component;
import
java.io.File
;
/**
* 直播首页操作
*
* @author 颜佐光
*/
@Component
public
class
MediaFirst
{
...
...
@@ -53,7 +58,7 @@ public class MediaFirst {
});
// 通过判断,当没有开启线程运行时,则开启线程运行
MediaResVo
res
=
this
.
getCache
().
start
(
req
,
new
Runnable
()
{
return
this
.
getCache
().
start
(
req
,
new
Runnable
()
{
@Override
public
void
run
()
{
// 开始开启线程运行
...
...
@@ -65,7 +70,6 @@ public class MediaFirst {
});
}
});
return
res
;
}
private
File
getFile
(
MediaReqVo
req
)
{
...
...
@@ -89,11 +93,10 @@ public class MediaFirst {
MediaResVo
res
=
cache
.
get
(
req
);
if
(
res
==
null
)
{
res
=
JsonHelper
.
to
(
req
,
MediaResVo
.
class
);
}
else
if
(
res
.
getCount
()
<
1
)
{
break
;
}
// 下载m3mu并转换成mp4
downM3mu
(
req
);
// 转换为图片
catImage
(
req
);
// 将下载临时文件移动到临时文件
cache
.
lockTempFile
(
req
,
new
Runnable
()
{
...
...
@@ -108,6 +111,11 @@ public class MediaFirst {
});
// 写入缓存
cache
.
sub
(
res
);
// 判断是否还有执行次数
if
(
res
.
getCount
()
<
1
)
{
break
;
}
// 等待下一次截图
ThreadHelper
.
sleep
(
res
.
getSplit
());
}
while
(
true
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment