From 153b905185b40182978758d409accbb76f678cb1 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期四, 10 四月 2025 20:42:13 +0800 Subject: [PATCH] 修改视频直播方式为http-flv --- ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CarServiceImpl.java | 28 +++++++++++++++++++--------- 1 files changed, 19 insertions(+), 9 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 240dc19..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 @@ -31,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 @@ -39,8 +42,8 @@ @Service public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements ICarService { - @Value("${live.output.path}") - private String outputPath; + @Value("${live.hls.output-path}") + private String hlsOutputPath; @Resource private UPExgMsgRegisterClient upExgMsgRegisterClient; @@ -162,13 +165,20 @@ * 检测视频播放,清除没有播放的视频流 */ @Override - public void taskPlayDetection() { - List<Car> list = this.list(); - for (Car car : list) { - if(!redisTemplate.hasKey("live:" + car.getId())){ - String folderPath = outputPath + "hls\\" + car.getVehicleNumber(); - JavaCVStreamUtil.close(car.getId(), folderPath); - } + 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