diff --git a/CHANGELOG.md b/CHANGELOG.md index 4da92ec..40a9e87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +- Audioplayer not stopping properly + ## [2.8.1] - 2024-04-28 ### Fixed diff --git a/src/services/player.ts b/src/services/player.ts index 2ec177c..0da80a4 100644 --- a/src/services/player.ts +++ b/src/services/player.ts @@ -126,7 +126,7 @@ export default class { this.loopCurrentSong = false; this.voiceConnection.destroy(); - this.audioPlayer?.stop(); + this.audioPlayer?.stop(true); this.voiceConnection = null; this.audioPlayer = null; @@ -280,7 +280,7 @@ export default class { if (this.getCurrent() && this.status !== STATUS.PAUSED) { await this.play(); } else { - this.audioPlayer?.stop(); + this.audioPlayer?.stop(true); this.status = STATUS.IDLE; const settings = await getGuildSettings(this.guildId); @@ -429,6 +429,12 @@ export default class { } private async getStream(song: QueuedSong, options: {seek?: number; to?: number} = {}): Promise { + if (this.status === STATUS.PLAYING) { + this.audioPlayer?.stop(); + } else if (this.status === STATUS.PAUSED) { + this.audioPlayer?.stop(true); + } + if (song.source === MediaSource.HLS) { return this.createReadStream({url: song.url, cacheKey: song.url}); } @@ -619,7 +625,10 @@ export default class { stream.pipe(capacitor); returnedStream.on('close', () => { - stream.kill('SIGKILL'); + if (!options.cache) { + stream.kill('SIGKILL'); + } + hasReturnedStreamClosed = true; });