🐛 Fix track state on finishing track

This commit is contained in:
Manuel 2023-03-28 22:17:59 +02:00 committed by Manuel
parent 00e58dcc8d
commit b940ca98e2
3 changed files with 15 additions and 1 deletions

View File

@ -266,6 +266,7 @@ export class DiscordVoiceService {
const playlist = this.playbackService.getPlaylistOrDefault();
const finishedTrack = playlist.getActiveTrack();
finishedTrack.playing = false;
this.eventEmitter.emit('internal.audio.track.finish', finishedTrack);

View File

@ -10,7 +10,7 @@ import { getSessionApi } from '@jellyfin/sdk/lib/utils/api/session-api';
import { Injectable, Logger } from '@nestjs/common';
import { OnEvent } from '@nestjs/event-emitter';
import { Track } from 'src/models/shared/Track';
import { Track } from '../../models/shared/Track';
import { PlaybackService } from '../../playback/playback.service';

View File

@ -92,12 +92,21 @@ export class Playlist {
return 0;
}
const previousTrackLength = this.tracks.length;
this.eventEmitter.emit('controls.playlist.tracks.enqueued', {
count: tracks.length,
activeTrack: this.activeTrackIndex,
});
const length = this.tracks.push(...tracks);
// existing tracks are in the playlist, but none are playing. play the first track out of the new tracks
if (!this.hasAnyPlaying() && tracks.length > 0) {
this.activeTrackIndex = previousTrackLength;
this.announceTrackChange();
return length;
}
// emit a track change if there is no item
if (this.activeTrackIndex === undefined) {
this.announceTrackChange();
@ -128,6 +137,10 @@ export class Playlist {
this.activeTrackIndex = undefined;
}
private hasAnyPlaying() {
return this.tracks.some((track) => track.playing);
}
private announceTrackFinishIfSet() {
if (this.activeTrackIndex === undefined) {
return;