Skip to content

Commit

Permalink
Stop audioplayer properly (#1032)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoCoreDuo committed Jun 13, 2024
1 parent cc0cf83 commit 29b61cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions src/services/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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});
}
Expand Down Expand Up @@ -619,7 +625,10 @@ export default class {
stream.pipe(capacitor);

returnedStream.on('close', () => {
stream.kill('SIGKILL');
if (!options.cache) {
stream.kill('SIGKILL');
}

hasReturnedStreamClosed = true;
});

Expand Down

0 comments on commit 29b61cc

Please sign in to comment.