mirror of
https://github.com/Coloryr/AllMusic.git
synced 2026-11-08 18:54:44 +00:00
完整退出线程
This commit is contained in:
1 parent
b53be33df2
commit
4245951633
3 files changed
+23
-15
No files matched your search
@@ -20,7 +20,7 @@ permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
build_client:
|
||||
build_onejar:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
|
||||
@@ -82,6 +82,8 @@ public class AllMusicHud {
|
||||
private BufferedImage bg2;
|
||||
private boolean isRun;
|
||||
|
||||
private final ScheduledExecutorService service1;
|
||||
|
||||
/**
|
||||
* 是否有图片
|
||||
*/
|
||||
@@ -112,14 +114,10 @@ public class AllMusicHud {
|
||||
thread.setName("allmusic_pic");
|
||||
thread.start();
|
||||
|
||||
ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
|
||||
service.scheduleAtFixedRate(this::picRotateTick, 0, 1, TimeUnit.MILLISECONDS);
|
||||
|
||||
service = Executors.newSingleThreadScheduledExecutor();
|
||||
service.scheduleAtFixedRate(this::lyricTick, 0, 10, TimeUnit.MILLISECONDS);
|
||||
|
||||
service = Executors.newSingleThreadScheduledExecutor();
|
||||
service.scheduleAtFixedRate(this::loopTick, 0, 100, TimeUnit.MILLISECONDS);
|
||||
service1 = Executors.newScheduledThreadPool(3);
|
||||
service1.scheduleAtFixedRate(this::picRotateTick, 0, 1, TimeUnit.MILLISECONDS);
|
||||
service1.scheduleAtFixedRate(this::lyricTick, 0, 10, TimeUnit.MILLISECONDS);
|
||||
service1.scheduleAtFixedRate(this::loopTick, 0, 100, TimeUnit.MILLISECONDS);
|
||||
|
||||
picRender = AllMusicCore.bridge.makePictureRender(size);
|
||||
|
||||
@@ -151,6 +149,8 @@ public class AllMusicHud {
|
||||
|
||||
public void stop() {
|
||||
isRun = false;
|
||||
service1.close();
|
||||
semaphore.release();
|
||||
}
|
||||
|
||||
public static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) {
|
||||
|
||||
@@ -60,6 +60,7 @@ public class AllMusicPlayer extends InputStream {
|
||||
|
||||
public void stop() {
|
||||
isRun = false;
|
||||
isClose = true;
|
||||
semaphore.release();
|
||||
semaphoreReload.release();
|
||||
scheduler.close();
|
||||
@@ -157,8 +158,8 @@ public class AllMusicPlayer extends InputStream {
|
||||
|
||||
resetSource();
|
||||
|
||||
nowTask = tasks.pop();
|
||||
if (nowTask == null || nowTask.url == null || nowTask.url.isEmpty()) continue;
|
||||
PlayTaskObj task = tasks.pop();
|
||||
if (task == null || task.url == null || task.url.isEmpty()) continue;
|
||||
tasks.clear();
|
||||
try {
|
||||
local = 0;
|
||||
@@ -193,18 +194,24 @@ public class AllMusicPlayer extends InputStream {
|
||||
int frequency = decoder.getOutputFrequency();
|
||||
int channels = decoder.getOutputChannels();
|
||||
if (channels != 1 && channels != 2) continue;
|
||||
if (nowTask.time != 0) {
|
||||
decoder.set(nowTask.time);
|
||||
if (task.time != 0) {
|
||||
decoder.set(task.time);
|
||||
}
|
||||
reload = false;
|
||||
isClose = false;
|
||||
int chatCount = 0;
|
||||
|
||||
while (true) {
|
||||
if (!isRun) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (isClose) break;
|
||||
|
||||
while (AL10.alGetSourcei(index, AL10.AL_BUFFERS_QUEUED) < AllMusicCore.config.queueSize) {
|
||||
if (!isRun) {
|
||||
return;
|
||||
}
|
||||
if (isClose) break;
|
||||
BuffPack output = decoder.decodeFrame();
|
||||
if (output == null) break;
|
||||
@@ -279,7 +286,7 @@ public class AllMusicPlayer extends InputStream {
|
||||
break;
|
||||
}
|
||||
if (reload) {
|
||||
tasks.push(nowTask);
|
||||
tasks.push(task);
|
||||
semaphore.release();
|
||||
continue;
|
||||
}
|
||||
@@ -297,7 +304,8 @@ public class AllMusicPlayer extends InputStream {
|
||||
queued--;
|
||||
}
|
||||
} else {
|
||||
tasks.push(nowTask);
|
||||
tasks.push(task);
|
||||
index = -1;
|
||||
semaphore.release();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in new issue
Block a user