Stop audioplayer properly (#1032)

This commit is contained in:
MarcoCoreDuo 2024-06-13 07:25:35 +02:00 committed by GitHub
parent cc0cf8379c
commit 29b61cc0b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 3 deletions

View file

@ -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<Readable> {
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;
});