重启顺序

This commit is contained in:
Color_yr committed 2026-07-24 00:04:23 +08:00
1 parent 210499103f
commit 304e01b5f9
9 files changed
+104 -110

No files matched your search

@@ -1,7 +1,6 @@
package com.coloryr.allmusic.client.core;
import com.coloryr.allmusic.client.core.objs.ConfigObj;
import com.coloryr.allmusic.client.core.player.AllMusicPlayer;
import com.coloryr.allmusic.codec.CommandType;
import com.coloryr.allmusic.codec.HudPosObj;
import com.coloryr.allmusic.codec.MusicPack;
@@ -26,6 +25,8 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
/**
* AllMusic核心
@@ -52,6 +53,8 @@ public class AllMusicCore {
*/
private static AllMusicHud hud;
public static final ScheduledExecutorService service = Executors.newScheduledThreadPool(4);
/**
* 更新音频缓存
*/
@@ -135,6 +138,8 @@ public class AllMusicCore {
}
public static void stop() {
service.close();
if (player != null) {
player.stop();
}
@@ -82,8 +82,6 @@ public class AllMusicHud {
private BufferedImage bg2;
private boolean isRun;
private final ScheduledExecutorService service1;
/**
* 是否有图片
*/
@@ -114,10 +112,9 @@ public class AllMusicHud {
thread.setName("allmusic_pic");
thread.start();
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);
AllMusicCore.service.scheduleAtFixedRate(this::picRotateTick, 0, 1, TimeUnit.MILLISECONDS);
AllMusicCore.service.scheduleAtFixedRate(this::lyricTick, 0, 10, TimeUnit.MILLISECONDS);
AllMusicCore.service.scheduleAtFixedRate(this::loopTick, 0, 100, TimeUnit.MILLISECONDS);
picRender = AllMusicCore.bridge.makePictureRender(size);
@@ -149,7 +146,6 @@ public class AllMusicHud {
public void stop() {
isRun = false;
service1.close();
semaphore.release();
}
@@ -1,6 +1,5 @@
package com.coloryr.allmusic.client.core.player;
package com.coloryr.allmusic.client.core;
import com.coloryr.allmusic.client.core.AllMusicCore;
import com.coloryr.allmusic.client.core.objs.PlayTaskObj;
import com.coloryr.allmusic.client.core.player.decoder.BuffPack;
import com.coloryr.allmusic.client.core.player.decoder.IDecoder;
@@ -41,21 +40,16 @@ public class AllMusicPlayer extends InputStream {
private boolean isPlay = false;
private boolean wait = false;
private int index = -1;
private IntBuffer source;
private final IntBuffer source;
private long local;
private boolean isRun;
private boolean isChat;
private ScheduledExecutorService scheduler;
private int chatCount = 0;
public AllMusicPlayer(IntBuffer source) {
try {
this.source = source;
new Thread(this::run, "allmusic_run").start();
scheduler = Executors.newSingleThreadScheduledExecutor();
scheduler.scheduleAtFixedRate(this::timerTick, 0, 10, TimeUnit.MILLISECONDS);
} catch (Exception e) {
e.printStackTrace();
}
this.source = source;
new Thread(this::run, "allmusic_run").start();
AllMusicCore.service.scheduleAtFixedRate(this::timerTick, 0, 10, TimeUnit.MILLISECONDS);
}
public void stop() {
@@ -63,7 +57,6 @@ public class AllMusicPlayer extends InputStream {
isClose = true;
semaphore.release();
semaphoreReload.release();
scheduler.close();
}
public void setChat() {
@@ -84,12 +77,9 @@ public class AllMusicPlayer extends InputStream {
if (nowTask == null) {
return;
}
String url = nowTask.url;
closePlayer();
PlayTaskObj task = new PlayTaskObj();
task.url = url;
task.time = time;
tasks.push(task);
isClose = true;
nowTask.time = time;
tasks.push(nowTask);
semaphore.release();
}
@@ -110,23 +100,49 @@ public class AllMusicPlayer extends InputStream {
}
private void resetSource() {
if (index != -1) {
AL10.alSourceStop(index);
AL10.alSourcei(index, AL10.AL_BUFFER, AL10.AL_NONE);
AL10.alSourceStop(index);
AL10.alSourcei(index, AL10.AL_BUFFER, AL10.AL_NONE);
int queued;
do {
queued = AL10.alGetSourcei(index, AL10.AL_BUFFERS_QUEUED);
if (queued > 0) {
int buffer = AL10.alSourceUnqueueBuffers(index);
if (buffer != 0) {
AL10.alDeleteBuffers(buffer);
}
int queued;
do {
queued = AL10.alGetSourcei(index, AL10.AL_BUFFERS_QUEUED);
if (queued > 0) {
int buffer = AL10.alSourceUnqueueBuffers(index);
if (buffer != 0) {
AL10.alDeleteBuffers(buffer);
}
} while (queued > 0);
}
} while (queued > 0);
}
AL10.alSourcef(index, AL10.AL_GAIN, AllMusicCore.bridge.getVolume());
AL10.alSourcef(index, AL10.AL_PITCH, 1.0f);
private void checkChat() {
if (isChat) {
chatCount++;
if (chatCount >= 200) {
isChat = false;
chatCount = 0;
}
}
}
private void dequeue() {
int processed = AL10.alGetSourcei(index, AL10.AL_BUFFERS_PROCESSED);
for (int i = 0; i < processed; i++) {
int buffer = AL10.alSourceUnqueueBuffers(index);
if (buffer != 0) {
AL10.alDeleteBuffers(buffer);
}
}
}
private void checkVolume() {
float temp = AllMusicCore.bridge.getVolume();
float now = AL10.alGetSourcef(index, AL10.AL_GAIN);
if (isChat) {
temp *= 0.2F;
}
if (now != temp) {
AL10.alSourcef(index, AL10.AL_GAIN, temp);
}
}
@@ -156,10 +172,11 @@ public class AllMusicPlayer extends InputStream {
}
}
dequeue();
resetSource();
PlayTaskObj task = tasks.pop();
if (task == null || task.url == null || task.url.isEmpty()) continue;
nowTask = tasks.pop();
if (nowTask == null || nowTask.url == null || nowTask.url.isEmpty()) continue;
tasks.clear();
try {
local = 0;
@@ -194,25 +211,27 @@ public class AllMusicPlayer extends InputStream {
int frequency = decoder.getOutputFrequency();
int channels = decoder.getOutputChannels();
if (channels != 1 && channels != 2) continue;
if (task.time != 0) {
decoder.set(task.time);
if (nowTask.time != 0) {
decoder.set(nowTask.time);
}
reload = false;
isClose = false;
int chatCount = 0;
while (true) {
if (!isRun) {
return;
}
if (isClose) {
break;
}
try {
if (isClose) break;
while (AL10.alGetSourcei(index, AL10.AL_BUFFERS_QUEUED) < AllMusicCore.config.queueSize) {
if (!isRun) {
return;
}
if (isClose) break;
if (isClose) {
break;
}
BuffPack output = decoder.decodeFrame();
if (output == null) break;
ByteBuffer byteBuffer = BufferUtils.createByteBuffer(output.len)
@@ -238,32 +257,11 @@ public class AllMusicPlayer extends InputStream {
}
}
float temp = AllMusicCore.bridge.getVolume();
float now = AL10.alGetSourcef(index, AL10.AL_GAIN);
if (isChat) {
temp *= 0.2F;
}
if (now != temp) {
AL10.alSourcef(index, AL10.AL_GAIN, temp);
}
int processed = AL10.alGetSourcei(index, AL10.AL_BUFFERS_PROCESSED);
for (int i = 0; i < processed; i++) {
int buffer = AL10.alSourceUnqueueBuffers(index);
if (buffer != 0) {
AL10.alDeleteBuffers(buffer);
}
}
Thread.sleep(5);
if (isChat) {
chatCount++;
if (chatCount >= 200) {
isChat = false;
chatCount = 0;
}
}
checkChat();
checkVolume();
dequeue();
} catch (Exception e) {
if (!isClose) {
e.printStackTrace();
@@ -277,6 +275,9 @@ public class AllMusicPlayer extends InputStream {
while (!isClose && AL10.alGetSourcei(index, AL10.AL_SOURCE_STATE) == AL10.AL_PLAYING) {
Thread.sleep(50);
checkChat();
checkVolume();
dequeue();
}
if (!reload) {
@@ -286,26 +287,18 @@ public class AllMusicPlayer extends InputStream {
break;
}
if (reload) {
tasks.push(task);
tasks.push(nowTask);
semaphore.release();
continue;
}
}
isPlay = false;
AL10.alSourceStop(index);
AL10.alSourcei(index, AL10.AL_BUFFER, AL10.AL_NONE);
int queued = AL10.alGetSourcei(index, AL10.AL_BUFFERS_QUEUED);
while (queued > 0) {
int buffer = AL10.alSourceUnqueueBuffers(index);
if (buffer != 0) {
AL10.alDeleteBuffers(buffer);
}
queued--;
}
dequeue();
resetSource();
} else {
tasks.push(task);
index = -1;
tasks.push(nowTask);
semaphore.release();
}
} catch (Exception e) {
@@ -353,6 +346,13 @@ public class AllMusicPlayer extends InputStream {
}
}
public void setReload() {
if (isPlay) {
reload = true;
isClose = true;
}
}
@Override
public int read() throws IOException {
local++;
@@ -406,11 +406,4 @@ public class AllMusicPlayer extends InputStream {
this.local = local;
connect();
}
public void setReload() {
if (isPlay) {
reload = true;
isClose = true;
}
}
}
@@ -18,7 +18,7 @@
package com.coloryr.allmusic.client.core.player.decoder.flac;
import com.coloryr.allmusic.client.core.AllMusicCore;
import com.coloryr.allmusic.client.core.player.AllMusicPlayer;
import com.coloryr.allmusic.client.core.AllMusicPlayer;
import com.coloryr.allmusic.client.core.player.decoder.BuffPack;
import com.coloryr.allmusic.client.core.player.decoder.IDecoder;
@@ -17,7 +17,7 @@
package com.coloryr.allmusic.client.core.player.decoder.flac;
import com.coloryr.allmusic.client.core.player.AllMusicPlayer;
import com.coloryr.allmusic.client.core.AllMusicPlayer;
import java.io.BufferedInputStream;
import java.io.IOException;
@@ -27,7 +27,7 @@
package com.coloryr.allmusic.client.core.player.decoder.mp3;
import com.coloryr.allmusic.client.core.player.AllMusicPlayer;
import com.coloryr.allmusic.client.core.AllMusicPlayer;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -18,7 +18,7 @@
package com.coloryr.allmusic.client.core.player.decoder.mp3;
import com.coloryr.allmusic.client.core.player.AllMusicPlayer;
import com.coloryr.allmusic.client.core.AllMusicPlayer;
import com.coloryr.allmusic.client.core.player.decoder.BuffPack;
import com.coloryr.allmusic.client.core.player.decoder.IDecoder;
@@ -1,7 +1,7 @@
package com.coloryr.allmusic.client.core.player.decoder.ogg;
import com.coloryr.allmusic.client.core.AllMusicCore;
import com.coloryr.allmusic.client.core.player.AllMusicPlayer;
import com.coloryr.allmusic.client.core.AllMusicPlayer;
import com.coloryr.allmusic.client.core.player.decoder.BuffPack;
import com.coloryr.allmusic.client.core.player.decoder.IDecoder;
import com.coloryr.allmusic.client.core.player.decoder.ogg.jcraft.jogg.Packet;
+13 -13
View File
@@ -55,19 +55,19 @@ include(":server:folia")
include(":server:paper")
include(":server:velocity")
include(":onejar")
include(":onejar:fabric_1_16_5")
include(":onejar:fabric_1_20_1")
include(":onejar:fabric_1_21")
include(":onejar:fabric_1_21_6")
include(":onejar:fabric_1_21_11")
include(":onejar:fabric_26_1")
include(":onejar:fabric_26_2")
include(":onejar:neoforge_1_21")
include(":onejar:neoforge_1_21_6")
include(":onejar:neoforge_1_21_11")
include(":onejar:neoforge_26_1")
//include(":onejar")
//
//include(":onejar:fabric_1_16_5")
//include(":onejar:fabric_1_20_1")
//include(":onejar:fabric_1_21")
//include(":onejar:fabric_1_21_6")
//include(":onejar:fabric_1_21_11")
//include(":onejar:fabric_26_1")
//include(":onejar:fabric_26_2")
//include(":onejar:neoforge_1_21")
//include(":onejar:neoforge_1_21_6")
//include(":onejar:neoforge_1_21_11")
//include(":onejar:neoforge_26_1")
pluginManagement {
repositories {