From 2b4f8907a65c347400432c8db1bccb97c6a26d30 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期五, 11 四月 2025 15:30:50 +0800 Subject: [PATCH] 修改视频播放bug --- ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CarServiceImpl.java | 32 ++++++++++++++++++++++++++++++++ 1 files changed, 32 insertions(+), 0 deletions(-) diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CarServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CarServiceImpl.java index e4ec30f..71f10ed 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CarServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CarServiceImpl.java @@ -19,6 +19,8 @@ import com.ruoyi.system.service.ICarTypeService; import com.ruoyi.system.service.IDriverService; import com.ruoyi.system.service.IEnterpriseService; +import com.ruoyi.system.util.JavaCVStreamUtil; +import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; @@ -29,6 +31,9 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; /** * @author zhibing.pu @@ -36,6 +41,9 @@ */ @Service public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements ICarService { + + @Value("${live.hls.output-path}") + private String hlsOutputPath; @Resource private UPExgMsgRegisterClient upExgMsgRegisterClient; @@ -151,4 +159,28 @@ } } } + + + /** + * 检测视频播放,清除没有播放的视频流 + */ + @Override + public void taskPlayDetection(Integer deviceNumber) { + Car car = this.getById(deviceNumber); + try { + ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1); + executorService.scheduleWithFixedDelay(new Runnable() { + @Override + public void run() { + if(!redisTemplate.hasKey("live:" + car.getId())){ + String folderPath = hlsOutputPath + "hls\\" + car.getVehicleNumber(); + JavaCVStreamUtil.close(car.getId(), folderPath); + } + }}, 1, 1, TimeUnit.MINUTES); + }catch (Exception e){ + e.printStackTrace(); + } + } + + } -- Gitblit v1.7.1