Skip to content

Commit

Permalink
Fix hanging playback when no stream is available
Browse files Browse the repository at this point in the history
  • Loading branch information
sferra committed Feb 29, 2024
1 parent 1ec000a commit 6fabc2f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/app/app/actions/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ export const findStreamsForTrack = (index: number) => async (dispatch, getState)
...streamData.slice(1)
];

const firstStream = streamData[0];
if (!firstStream?.stream) {
removeFirstStream(track, index, streamData, dispatch);
return;
}

dispatch(
updateQueueItem({
...track,
Expand Down Expand Up @@ -237,6 +243,22 @@ export const findStreamsForTrack = (index: number) => async (dispatch, getState)
}
};

function removeFirstStream(track: QueueItem, trackIndex: number, streams: TrackStream[], dispatch) {
if (streams.length === 1) {
// no more streams are available
// return removeTrackAction(trackIndex);
dispatch(removeFromQueue(trackIndex));
} else {
// remove the first (unavailable) stream
dispatch(updateQueueItem({
...track,
loading: true,
error: false,
streams: streams.slice(1)
}));
}
}

export function playTrack(streamProviders, item: QueueItem) {
return (dispatch) => {
dispatch(clearQueue());
Expand Down

0 comments on commit 6fabc2f

Please sign in to comment.