🐛 Fix crash with empty playlists (#128)

This commit is contained in:
Manuel 2023-03-25 22:03:06 +01:00 committed by GitHub
parent c01ac56061
commit 2141880b44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -94,10 +94,14 @@ export class PlayItemCommand {
}
const tracks = await item.toTracks(this.jellyfinSearchService);
this.logger.debug(`Extracted ${tracks.length} tracks from the search item`);
const reducedDuration = tracks.reduce(
(sum, item) => sum + item.duration,
0,
);
this.logger.debug(
`Adding ${tracks.length} tracks with a duration of ${reducedDuration} ticks`,
);
this.playbackService.getPlaylistOrDefault().enqueueTracks(tracks);
const remoteImage: RemoteImageInfo | undefined = tracks

View File

@ -84,6 +84,10 @@ export class Playlist {
* @returns the new lendth of the tracks in the playlist
*/
enqueueTracks(tracks: Track[]) {
if (tracks.length === 0) {
return 0;
}
this.eventEmitter.emit('controls.playlist.tracks.enqueued', {
count: tracks.length,
activeTrack: this.activeTrackIndex,