Keep a tighter sync between Jellyfin's remote control and the state of the Discord player (#256)

* Keep a tighter sync between Jellyfin's remote control and the state of the Discord player

* Fix accidental omission
This commit is contained in:
sssionek 2023-11-23 21:32:58 +01:00 committed by GitHub
parent 390c6f145f
commit 941bc8745e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 5 deletions

View File

@ -129,6 +129,10 @@ export class DiscordVoiceService {
@OnEvent('internal.voice.controls.pause')
pause() {
this.createAndReturnOrGetAudioPlayer().pause();
const track = this.playbackService.getPlaylistOrDefault().getActiveTrack();
if(track) {
track.playing = false;
}
this.eventEmitter.emit('playback.state.pause', true);
}
@ -137,7 +141,13 @@ export class DiscordVoiceService {
*/
@OnEvent('internal.voice.controls.stop')
stop(force: boolean): boolean {
return this.createAndReturnOrGetAudioPlayer().stop(force);
const hasStopped = this.createAndReturnOrGetAudioPlayer().stop(force);
if (hasStopped) {
const playlist = this.playbackService.getPlaylistOrDefault();
this.eventEmitter.emit('internal.audio.track.finish', playlist.getActiveTrack());
playlist.clear();
}
return hasStopped;
}
/**
@ -145,6 +155,10 @@ export class DiscordVoiceService {
*/
unpause() {
this.createAndReturnOrGetAudioPlayer().unpause();
const track = this.playbackService.getPlaylistOrDefault().getActiveTrack();
if(track) {
track.playing = true;
}
this.eventEmitter.emit('playback.state.pause', false);
}

View File

@ -97,9 +97,9 @@ export class JellyinPlaystateService {
@Interval(1000)
private async onPlaybackProgress() {
const track = this.playbackService.getPlaylistOrDefault().getActiveTrack();
if (!track) {
const playlist = this.playbackService.getPlaylistOrDefault();
const track = playlist.getActiveTrack();
if (!track || !playlist.hasAnyPlaying()) {
return;
}

View File

@ -140,7 +140,7 @@ export class Playlist {
this.activeTrackIndex = undefined;
}
private hasAnyPlaying() {
hasAnyPlaying() {
return this.tracks.some((track) => track.playing);
}