From d311b8180530d5ceb8c0e768ac8a1dbcd2e32dbc Mon Sep 17 00:00:00 2001 From: Color_yr <402067010@qq.com> Date: Fri, 27 Mar 2026 18:17:49 +0800 Subject: [PATCH] =?UTF-8?q?up=20=E7=BA=BF=E7=A8=8B=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/AllMusic.java | 11 +++-- core/music/MusicSearch.java | 13 ++---- core/music/PlayMusic.java | 17 ++----- core/music/PlayRuntime.java | 93 ++++++++++++++----------------------- core/sql/DataSql.java | 14 +++--- version | 2 +- 6 files changed, 58 insertions(+), 92 deletions(-) diff --git a/core/AllMusic.java b/core/AllMusic.java index d6578a5b..ec1cd767 100644 --- a/core/AllMusic.java +++ b/core/AllMusic.java @@ -47,7 +47,7 @@ public class AllMusic { /** * 插件版本号 */ - public static final String version = "3.8.0"; + public static final String version = "3.9.0"; /** * 配置文件版本号 */ @@ -338,6 +338,8 @@ public class AllMusic { * 启动插件 */ public static void start() { + isRun = true; + MusicHttpClient.init(); IMusicApi api = new NetiApiMain(); @@ -355,13 +357,14 @@ public class AllMusic { * 停止插件 */ public static void stop() { + isRun = false; + PlayMusic.clearVote(); PlayMusic.clearPush(); - side.sendStop(); - MusicSearch.stop(); - PlayMusic.stop(); + PlayMusic.clear(); PlayRuntime.stop(); DataSql.stop(); + side.sendStop(); log.data("[AllMusic3]已停止,感谢使用"); } diff --git a/core/music/MusicSearch.java b/core/music/MusicSearch.java index 6b9a5cf1..327ed541 100644 --- a/core/music/MusicSearch.java +++ b/core/music/MusicSearch.java @@ -12,10 +12,10 @@ import java.util.concurrent.ConcurrentLinkedQueue; public class MusicSearch { private static final Queue tasks = new ConcurrentLinkedQueue<>(); - private static boolean isRun; private static void task() { - while (isRun) { + AllMusic.log.data("歌曲搜索线程启动"); + while (AllMusic.isRun) { try { PlayerAddMusicObj obj = tasks.poll(); if (obj != null) { @@ -40,16 +40,11 @@ public class MusicSearch { e.printStackTrace(); } } + AllMusic.log.data("歌曲搜索线程停止"); } public static void start() { - Thread taskT = new Thread(MusicSearch::task, "AllMusic_search"); - isRun = true; - taskT.start(); - } - - public static void stop() { - isRun = false; + new Thread(MusicSearch::task, "allmusic_search").start(); } public static void addSearch(PlayerAddMusicObj obj) { diff --git a/core/music/PlayMusic.java b/core/music/PlayMusic.java index cd8bb3cb..0e4c39a9 100644 --- a/core/music/PlayMusic.java +++ b/core/music/PlayMusic.java @@ -77,24 +77,13 @@ public class PlayMusic { * 插歌目标 */ private static SongInfoObj push; - private static boolean isRun; private static int idleNow; - /** - * 停止歌曲逻辑 - */ - public static void stop() { - PlayMusic.clear(); - isRun = false; - } - /** * 开始歌曲逻辑 */ public static void start() { - Thread addT = new Thread(PlayMusic::task, "AllMusicList"); - isRun = true; - addT.start(); + new Thread(PlayMusic::task, "allmusic_task").start(); } /** @@ -218,7 +207,8 @@ public class PlayMusic { } private static void task() { - while (isRun) { + AllMusic.log.data("歌曲处理线程启动"); + while (AllMusic.isRun) { try { PlayerAddMusicObj obj = tasks.poll(); if (obj != null) { @@ -233,6 +223,7 @@ public class PlayMusic { e.printStackTrace(); } } + AllMusic.log.data("歌曲处理线程关闭"); } /** diff --git a/core/music/PlayRuntime.java b/core/music/PlayRuntime.java index 1ff32636..67e04f02 100644 --- a/core/music/PlayRuntime.java +++ b/core/music/PlayRuntime.java @@ -18,7 +18,6 @@ public class PlayRuntime { */ private static int count = 0; private static int ping = 0; - private static boolean isRun; /** * 歌曲更新计数器 */ @@ -27,23 +26,21 @@ public class PlayRuntime { * 歌曲定时器 */ private static ScheduledExecutorService service; - /** - * 歌词定时器 - */ - private static ScheduledExecutorService service1; /** * 事务定时器 */ private static ScheduledExecutorService service2; + private static boolean isPlay; + /** * 启动歌曲工作 */ public static void start() { - Thread taskT = new Thread(PlayRuntime::musicPlayTask, "AllMusicPlay"); - isRun = true; - taskT.start(); + new Thread(PlayRuntime::musicPlayTask, "allMusic_play").start(); + service = Executors.newSingleThreadScheduledExecutor(); + service.scheduleAtFixedRate(PlayRuntime::time1, 0, 10, TimeUnit.MILLISECONDS); service2 = Executors.newSingleThreadScheduledExecutor(); service2.scheduleAtFixedRate(PlayRuntime::time3, 0, 1, TimeUnit.SECONDS); } @@ -52,40 +49,22 @@ public class PlayRuntime { * 停止歌曲工作 */ public static void stop() { - closeTimer(); - if (service2 != null) { - service2.shutdown(); - service2 = null; - } - isRun = false; - PlayMusic.musicLessTime = 0; - } - - private static void closeTimer() { if (service != null) { service.shutdown(); service = null; } - if (service1 != null) { - service1.shutdown(); - service1 = null; - } - } - - private static void startTimer() { - service = Executors.newSingleThreadScheduledExecutor(); - service.scheduleAtFixedRate(PlayRuntime::time1, 0, 10, TimeUnit.MILLISECONDS); - if (PlayMusic.lyric != null && PlayMusic.lyric.isHaveLyric()) { - service1 = Executors.newSingleThreadScheduledExecutor(); - service1.scheduleAtFixedRate(PlayRuntime::time2, 0, 2, TimeUnit.MILLISECONDS); + if (service2 != null) { + service2.shutdown(); + service2 = null; } + PlayMusic.musicLessTime = 0; } /** * 清空歌曲数据 */ private static void clear() { - closeTimer(); + isPlay = false; PlayMusic.musicNowTime = 0; PlayMusic.musicAllTime = 0; PlayMusic.musicLessTime = 0; @@ -102,37 +81,35 @@ public class PlayRuntime { * 歌曲时间定时器 */ private static void time1() { - PlayMusic.musicNowTime += 10; - count++; - if (count == 100) { - PlayMusic.musicLessTime--; - count = 0; + if (isPlay) { + PlayMusic.musicNowTime += 10; + count++; + if (count == 100) { + PlayMusic.musicLessTime--; + count = 0; + } } - } - /** - * 歌词更新 - */ - private static void time2() { - try { - if (PlayMusic.lyric == null) - return; - boolean res = PlayMusic.lyric - .checkTime(PlayMusic.musicNowTime, AllMusic.getConfig().ktvMode); - if (res) { - times = 0; - HudUtils.sendHudLyricData(); - AllMusic.side.updateLyric(); - } else { - times++; - if (times == AllMusic.getConfig().sendDelay / 2 && PlayMusic.lyric != null) { + if (PlayMusic.lyric != null && PlayMusic.lyric.isHaveLyric()) { + try { + if (PlayMusic.lyric == null) + return; + boolean res = PlayMusic.lyric.checkTime(PlayMusic.musicNowTime, AllMusic.getConfig().ktvMode); + if (res) { times = 0; HudUtils.sendHudLyricData(); AllMusic.side.updateLyric(); + } else { + times++; + if (times == AllMusic.getConfig().sendDelay / 2 && PlayMusic.lyric != null) { + times = 0; + HudUtils.sendHudLyricData(); + AllMusic.side.updateLyric(); + } } + } catch (Exception e) { + e.printStackTrace(); } - } catch (Exception e) { - e.printStackTrace(); } } @@ -213,7 +190,8 @@ public class PlayRuntime { } private static void musicPlayTask() { - while (isRun) { + AllMusic.log.data("歌曲播放线程启动"); + while (AllMusic.isRun) { try { if (PlayMusic.getListSize() == 0) { if (PlayMusic.error >= 10) { @@ -258,7 +236,7 @@ public class PlayRuntime { if (PlayMusic.nowPlayMusic.getLength() != 0) { PlayMusic.musicAllTime = PlayMusic.musicLessTime = (PlayMusic.nowPlayMusic.getLength() / 1000) + 3; - startTimer(); + isPlay = true; AllMusic.side.sendMusic(PlayMusic.url); if (!AllMusic.getConfig().mutePlayMessage) { SongInfoObj music = PlayMusic.nowPlayMusic; @@ -311,5 +289,6 @@ public class PlayRuntime { e.printStackTrace(); } } + AllMusic.log.data("歌曲播放线程停止"); } } diff --git a/core/sql/DataSql.java b/core/sql/DataSql.java index 595391d5..98811038 100644 --- a/core/sql/DataSql.java +++ b/core/sql/DataSql.java @@ -81,7 +81,6 @@ public class DataSql { * 数据库文件 */ public static File sqlFile; - private static boolean isRun; /** * 数据库链接对象 */ @@ -731,26 +730,24 @@ public class DataSql { */ public static void start() { init(); - Thread thread = new Thread(DataSql::run); - isRun = true; - thread.start(); + new Thread(DataSql::run).start(); } /** * 停止数据库 */ public static void stop() { - isRun = false; semaphore.release(); } private static void run() { + AllMusic.log.data("数据库线程启动"); Runnable runnable; - while (isRun) { + while (AllMusic.isRun) { try { semaphore.acquire(); - if (!isRun) - return; + if (!AllMusic.isRun) + break; do { runnable = tasks.poll(); if (runnable != null) { @@ -762,5 +759,6 @@ public class DataSql { e.printStackTrace(); } } + AllMusic.log.data("数据库线程关闭"); } } diff --git a/version b/version index 0be1fc7d..b72ad011 100644 --- a/version +++ b/version @@ -1 +1 @@ -3.8.0 \ No newline at end of file +3.9.0 \ No newline at end of file