From 7896c9c9bfb56621dd583a336210c3a854d2a9c8 Mon Sep 17 00:00:00 2001 From: EvolvedGhost <727511070@qq.com> Date: Sat, 17 Oct 2026 23:35:23 +0800 Subject: [PATCH] fix(audio): fade out on stop command --- src/audio/player.ts | 17 +++++++++++++++++ src/bot/instance.ts | 6 ++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/audio/player.ts b/src/audio/player.ts index 50900d5..b4823c5 100644 --- a/src/audio/player.ts +++ b/src/audio/player.ts @@ -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); diff --git a/src/bot/instance.ts b/src/bot/instance.ts index e7bb2db..b2412cb 100755 --- a/src/bot/instance.ts +++ b/src/bot/instance.ts @@ -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();