mirror of
https://github.com/informaticker/discord-jellyfin-bot.git
synced 2024-11-24 18:41:57 +01:00
🐛 Fix track state on finishing track
This commit is contained in:
parent
00e58dcc8d
commit
b940ca98e2
@ -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);
|
||||
|
||||
|
@ -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';
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user