When start listening to a broadcast, pause the others (#9489)

This commit is contained in:
Michael Weimann 2022-10-24 16:06:58 +02:00 committed by GitHub
parent daf097e123
commit d702f4a291
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 186 additions and 61 deletions

View file

@ -47,7 +47,10 @@ export enum VoiceBroadcastPlaybackEvent {
interface EventMap {
[VoiceBroadcastPlaybackEvent.LengthChanged]: (length: number) => void;
[VoiceBroadcastPlaybackEvent.StateChanged]: (state: VoiceBroadcastPlaybackState) => void;
[VoiceBroadcastPlaybackEvent.StateChanged]: (
state: VoiceBroadcastPlaybackState,
playback: VoiceBroadcastPlayback
) => void;
[VoiceBroadcastPlaybackEvent.InfoStateChanged]: (state: VoiceBroadcastInfoState) => void;
}
@ -217,14 +220,20 @@ export class VoiceBroadcastPlayback
}
public pause(): void {
if (!this.currentlyPlaying) return;
// stopped voice broadcasts cannot be paused
if (this.getState() === VoiceBroadcastPlaybackState.Stopped) return;
this.setState(VoiceBroadcastPlaybackState.Paused);
if (!this.currentlyPlaying) return;
this.currentlyPlaying.pause();
}
public resume(): void {
if (!this.currentlyPlaying) return;
if (!this.currentlyPlaying) {
// no playback to resume, start from the beginning
this.start();
return;
}
this.setState(VoiceBroadcastPlaybackState.Playing);
this.currentlyPlaying.play();
@ -260,7 +269,7 @@ export class VoiceBroadcastPlayback
}
this.state = state;
this.emit(VoiceBroadcastPlaybackEvent.StateChanged, state);
this.emit(VoiceBroadcastPlaybackEvent.StateChanged, state, this);
}
public getInfoState(): VoiceBroadcastInfoState {