Play shuffled playlist, fixes #302

This commit is contained in:
James Barnsley
2018-06-26 08:51:11 +12:00
parent 1d492bbfef
commit 8ede56d876
11 changed files with 22918 additions and 20901 deletions

View File

@ -246,10 +246,11 @@ export function enqueueURIsBatchDone(){
}
}
export function playPlaylist(uri){
export function playPlaylist(uri, shuffle = false){
return {
type: 'MOPIDY_PLAY_PLAYLIST',
uri: uri
uri: uri,
shuffle: shuffle
}
}

View File

@ -546,14 +546,14 @@ const MopidyMiddleware = (function(){
// make sure we didn't get this playlist from Mopidy-Spotify
// if we did, we'd have a cached version on server so no need to fetch
if (!store.getState().core.playlists[action.uri].is_mopidy){
store.dispatch(spotifyActions.getPlaylistTracksAndPlay(action.uri))
store.dispatch(spotifyActions.getPlaylistTracksAndPlay(action.uri, action.shuffle))
break
}
// it's a spotify playlist that we haven't loaded
// we need to fetch via HTTP API to avoid timeout
} else if (helpers.uriSource(action.uri) == 'spotify' && store.getState().spotify.enabled){
store.dispatch(spotifyActions.getPlaylistTracksAndPlay(action.uri))
store.dispatch(spotifyActions.getPlaylistTracksAndPlay(action.uri, action.shuffle))
break
// Not in index, and Spotify HTTP not enabled, so just play it as-is
@ -567,7 +567,10 @@ const MopidyMiddleware = (function(){
if (response.tracks === undefined){
store.dispatch(uiActions.createNotification({content: 'Failed to load playlist tracks', type: 'bad'}));
} else {
var tracks_uris = helpers.arrayOf('uri',response.tracks)
var tracks_uris = helpers.arrayOf('uri',response.tracks);
if (action.shuffle){
tracks_uris = helpers.shuffle(tracks_uris);
}
store.dispatch(mopidyActions.playURIs(tracks_uris, action.uri))
}
},

View File

@ -1655,14 +1655,15 @@ export function getLibraryTracksAndPlayProcessor(data){
* Recursively get .next until we have all tracks
**/
export function getPlaylistTracksAndPlay(uri){
export function getPlaylistTracksAndPlay(uri, shuffle){
return (dispatch, getState) => {
dispatch(uiActions.startProcess(
'SPOTIFY_GET_PLAYLIST_TRACKS_AND_PLAY_PROCESSOR',
'Loading playlist tracks',
{
uri: uri,
next: 'users/'+ helpers.getFromUri('userid',uri) +'/playlists/'+ helpers.getFromUri('playlistid',uri) +'/tracks?market='+getState().spotify.country
next: 'users/'+ helpers.getFromUri('userid',uri) +'/playlists/'+ helpers.getFromUri('playlistid',uri) +'/tracks?market='+getState().spotify.country,
shuffle: shuffle
}
))
}
@ -1704,17 +1705,24 @@ export function getPlaylistTracksAndPlayProcessor(data){
{
next: response.next,
total: response.total,
remaining: response.total - uris.length
remaining: response.total - uris.length,
shuffle: data.shuffle
}
))
dispatch(uiActions.runProcess(
'SPOTIFY_GET_PLAYLIST_TRACKS_AND_PLAY_PROCESSOR',
{
next: response.next,
uris: uris
uris: uris,
shuffle: data.shuffle
}
))
} else {
if (data.shuffle){
uris = helpers.shuffle(uris);
}
dispatch(mopidyActions.playURIs(uris, data.uri))
dispatch(uiActions.processFinishing('SPOTIFY_GET_PLAYLIST_TRACKS_AND_PLAY_PROCESSOR'))
}