Skip to content

Commit

Permalink
fix(Voice): fix premature closed stream when seek during pause
Browse files Browse the repository at this point in the history
  • Loading branch information
skick1234 committed Feb 22, 2025
1 parent c022244 commit 458fd8e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/core/DisTubeVoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class DisTubeVoice extends TypedEmitter<DisTubeVoiceEvents> {
emittedError!: boolean;
isDisconnected = false;
stream?: DisTubeStream;
pausingStream?: DisTubeStream;
#channel!: VoiceBasedChannel;
#volume = 100;
constructor(voiceManager: DisTubeVoiceManager, channel: VoiceBasedChannel) {
Expand Down Expand Up @@ -171,11 +172,15 @@ export class DisTubeVoice extends TypedEmitter<DisTubeVoiceEvents> {
this.emittedError = true;
this.emit("error", error);
});
if (this.audioPlayer.state.status !== AudioPlayerStatus.Paused) this.audioPlayer.play(dtStream.audioResource);
this.stream?.kill();
if (this.audioPlayer.state.status !== AudioPlayerStatus.Paused) {
this.audioPlayer.play(dtStream.audioResource);
this.stream?.kill();
dtStream.spawn();
} else if (!this.pausingStream) {
this.pausingStream = this.stream;
}
this.stream = dtStream;
this.volume = this.#volume;
dtStream.spawn();
}
set volume(volume: number) {
if (typeof volume !== "number" || isNaN(volume)) {
Expand Down Expand Up @@ -207,6 +212,9 @@ export class DisTubeVoice extends TypedEmitter<DisTubeVoiceEvents> {
if (state.status !== AudioPlayerStatus.Paused) return;
if (this.stream?.audioResource && state.resource !== this.stream.audioResource) {
this.audioPlayer.play(this.stream.audioResource);
this.stream.spawn();
this.pausingStream?.kill();
delete this.pausingStream;
} else {
this.audioPlayer.unpause();
}
Expand Down

0 comments on commit 458fd8e

Please sign in to comment.