fix(audio): fade out on stop command

This commit is contained in:
EvolvedGhost committed 2026-10-17 23:35:23 +08:00
1 parent a0f0b49a4e
commit 7896c9c9bf
2 files changed
+21 -2

No files matched your search

+17
View File
@@ -209,6 +209,7 @@ export class AudioPlayer extends EventEmitter {
private transitionSilence = false;
private pauseFrames = 0;
private resumeSilenceFrames = 0;
private stopAfterPauseTail = false;
private transportRampStart: number | null = null;
private transportRampEnd: number | null = null;
private transportRampFrom = 1;
@@ -594,10 +595,22 @@ export class AudioPlayer extends EventEmitter {
this.onExternalEnd = null;
}
stopWithFade(): void {
if (this.state !== "playing" || this.externalMode) {
this.stop();
return;
}
this.stopAfterPauseTail = true;
this.pauseFrames = 9;
this.setTransportRamp(0, 0, 5);
this.state = "paused";
}
stop(keepAlive = false): void {
const wasRunning = this.frameLoopRunning;
const deadline = this.nextFrameTime;
this.transitionSilence = keepAlive;
this.stopAfterPauseTail = false;
// 3. 递增 ID 是最有效的逻辑“隔离墙”
this.sessionId++;
this.frameLoopRunning = false;
@@ -699,6 +712,10 @@ export class AudioPlayer extends EventEmitter {
else this.emitSilenceFrame(false);
} else {
this.nextFrameTime = performance.now();
if (this.stopAfterPauseTail) {
this.stop();
return;
}
}
}
else if (this.state === "idle" && this.transitionSilence) this.emitSilenceFrame(false);
+4 -2
View File
@@ -1547,11 +1547,13 @@ export class BotInstance extends EventEmitter {
private cmdStop(): string {
// Read the current song BEFORE queue.clear() so we can tell whether the
// sidecar needs stopping.
if (this.queue.current()?.platform === "spotify") {
const isSpotify = this.queue.current()?.platform === "spotify";
if (isSpotify) {
this.spotifyController.stop();
}
this.currentSourceIsSpotify = false;
this.player.stop();
if (isSpotify) this.player.stop();
else this.player.stopWithFade();
this.jellyfinReporter?.onStop();
this.autoPaused = false;
this.queue.clear();