From 25185be6fe45bade53ad1be88201b4b1d6450306 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Fri, 25 Oct 2024 17:47:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bilibili/Controllers/LiveDanmuController.java | 5 +++-- .../yutou/bilibili/services/LiveDanmuService.java | 8 ++++---- .../com/yutou/bilibili/services/SystemService.java | 14 ++++++-------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/yutou/bilibili/Controllers/LiveDanmuController.java b/src/main/java/com/yutou/bilibili/Controllers/LiveDanmuController.java index b91022a..f5342dc 100644 --- a/src/main/java/com/yutou/bilibili/Controllers/LiveDanmuController.java +++ b/src/main/java/com/yutou/bilibili/Controllers/LiveDanmuController.java @@ -25,16 +25,17 @@ public class LiveDanmuController { @ResponseBody @RequestMapping("/live/danmu/stop") public JSONObject stopLiveDanmu(String roomId) { - service.stop(roomId); + service.stop(roomId,true); return ResultData.success(ReturnCode.RC100); } @ResponseBody @RequestMapping("/live/danmu/start") public JSONObject startLiveDanmu(String roomId) { - service.start(roomId); + service.start(roomId, true); return ResultData.success(ReturnCode.RC100); } + @ResponseBody @RequestMapping("/live/danmu/file/list") public JSONObject getDanmuList(String roomId) { diff --git a/src/main/java/com/yutou/bilibili/services/LiveDanmuService.java b/src/main/java/com/yutou/bilibili/services/LiveDanmuService.java index 6395458..778b477 100644 --- a/src/main/java/com/yutou/bilibili/services/LiveDanmuService.java +++ b/src/main/java/com/yutou/bilibili/services/LiveDanmuService.java @@ -21,12 +21,12 @@ import java.util.List; @Service public class LiveDanmuService { - public void start(String roomId) { - WebSocketManager.getInstance().addRoom(LiveRoomConfig.buildConfig(roomId), true); + public void start(String roomId,boolean isUser) { + WebSocketManager.getInstance().addRoom(LiveRoomConfig.buildConfig(roomId), isUser); } - public void stop(String roomId) { - WebSocketManager.getInstance().stopRoom(roomId, true); + public void stop(String roomId,boolean isUser) { + WebSocketManager.getInstance().stopRoom(roomId, isUser); } public JSONArray getLiveRoomList() { diff --git a/src/main/java/com/yutou/bilibili/services/SystemService.java b/src/main/java/com/yutou/bilibili/services/SystemService.java index cfc89a3..22bdb60 100644 --- a/src/main/java/com/yutou/bilibili/services/SystemService.java +++ b/src/main/java/com/yutou/bilibili/services/SystemService.java @@ -29,6 +29,8 @@ import java.util.concurrent.TimeUnit; public class SystemService { @Resource LiveVideoService videoService; + @Resource + LiveDanmuService danmuService; SystemConfigDatabases databases = new SystemConfigDatabases(); private ScheduledExecutorService timer; private ScheduledFuture scheduled; @@ -52,7 +54,7 @@ public class SystemService { } scheduled = timer.scheduleAtFixedRate(() -> { List list = liveConfigDatabase.getAllConfig(); - System.out.println("循环任务:"+list.size()); + System.out.println("循环任务:" + list.size()); for (LiveConfigDatabaseBean bean : list) { if (bean.isRecordDanmu() && bean.checkRecordDanmuTime()) { recordDanmu(bean); @@ -63,19 +65,15 @@ public class SystemService { } }, 0, getLoopTimer(), TimeUnit.MILLISECONDS); } + public void stop() { scheduled.cancel(true); videoService.stopAll(); } + // 录制弹幕 private void recordDanmu(LiveConfigDatabaseBean bean) { - LiveRoomConfig config = new LiveRoomConfig(); - config.setLoginUid(bean.getRecordUid()); - config.setRoomId(bean.getRoomId()); - config.setAnchorName(bean.getAnchorName()); - config.setLogin(StringUtils.hasText(bean.getRecordUid())); - config.setRootPath(bean.getRecordPath()); - WebSocketManager.getInstance().addRoom(config,false); + danmuService.start(bean.getRoomId().toString(),false); } // 录制视频