Browse Source

Remove invalid songs from getRandomSongs

master
jeffvli 3 years ago
parent
commit
a230f605f1
  1. 23
      src/components/player/NowPlayingView.tsx

23
src/components/player/NowPlayingView.tsx

@ -179,16 +179,31 @@ const NowPlayingView = () => {
return notifyToast('error', errorMessages(res)[0]);
}
const cleanedSongs = res.song.filter((song: any) => {
// Remove invalid songs that may break the player
return song.bitRate && song.duration;
});
const difference = res.song.length - cleanedSongs.length;
if (action === 'play') {
dispatch(setPlayQueue({ entries: res.song }));
dispatch(setPlayQueue({ entries: cleanedSongs }));
dispatch(setStatus('PLAYING'));
notifyToast('info', `Playing ${res.song.length} song(s)`);
notifyToast(
'info',
`Playing ${cleanedSongs.length} ${
difference !== 0 ? `(-${difference} invalid)` : ''
} song(s)`
);
} else {
dispatch(appendPlayQueue({ entries: res.song }));
dispatch(appendPlayQueue({ entries: cleanedSongs }));
if (playQueue.entry.length < 1) {
dispatch(setStatus('PLAYING'));
}
notifyToast('info', `Added ${res.song.length} song(s) to the queue`);
notifyToast(
'info',
`Added ${cleanedSongs.length} ${difference !== 0 ? `(-${difference} invalid)` : ''} song(s)`
);
}
setIsLoadingRandom(false);

Loading…
Cancel
Save