Commit a5a428df authored by Edward Wang's avatar Edward Wang Committed by Jean-Baptiste Kempf

playlist: preserve first item when enabling random mode

Close #4472
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 126d1ccc
......@@ -45,11 +45,24 @@ static int RandomCallback( vlc_object_t *p_this, char const *psz_cmd,
{
(void)psz_cmd; (void)oldval; (void)newval; (void)a;
playlist_t *p_playlist = (playlist_t*)p_this;
bool random = newval.b_bool;
PL_LOCK;
pl_priv(p_playlist)->b_reset_currently_playing = true;
vlc_cond_signal( &pl_priv(p_playlist)->signal );
if( !random ) {
pl_priv(p_playlist)->b_reset_currently_playing = true;
vlc_cond_signal( &pl_priv(p_playlist)->signal );
} else {
/* Shuffle and sync the playlist on activation of random mode.
* This preserves the current playing item, so that the user
* can return to it if needed. (See #4472)
*/
playlist_private_t *p_sys = pl_priv(p_playlist);
playlist_item_t *p_new = p_sys->status.p_item;
ResetCurrentlyPlaying( p_playlist, NULL );
if( p_new )
ResyncCurrentIndex( p_playlist, p_new );
}
PL_UNLOCK;
return VLC_SUCCESS;
......
......@@ -149,6 +149,8 @@ int playlist_ItemRelease( playlist_item_t * );
int playlist_NodeEmpty( playlist_t *, playlist_item_t *, bool );
int playlist_DeleteItem( playlist_t * p_playlist, playlist_item_t *, bool);
void ResetCurrentlyPlaying( playlist_t *p_playlist, playlist_item_t *p_cur );
void ResyncCurrentIndex( playlist_t *p_playlist, playlist_item_t *p_cur );
/**
* @}
......
......@@ -144,7 +144,7 @@ static void UpdateActivity( playlist_t *p_playlist, int i_delta )
* \param p_cur the current playlist item
* \return nothing
*/
static void ResyncCurrentIndex( playlist_t *p_playlist, playlist_item_t *p_cur )
void ResyncCurrentIndex( playlist_t *p_playlist, playlist_item_t *p_cur )
{
PL_ASSERT_LOCKED;
......@@ -163,7 +163,14 @@ static void ResyncCurrentIndex( playlist_t *p_playlist, playlist_item_t *p_cur )
PL_DEBUG( "%s is at %i", PLI_NAME( p_cur ), p_playlist->i_current_index );
}
static void ResetCurrentlyPlaying( playlist_t *p_playlist,
/**
* Reset the currently playing playlist.
*
* \param p_playlist the playlist structure
* \param p_cur the current playlist item
* \return nothing
*/
void ResetCurrentlyPlaying( playlist_t *p_playlist,
playlist_item_t *p_cur )
{
playlist_private_t *p_sys = pl_priv(p_playlist);
......@@ -540,6 +547,7 @@ static void LoopRequest( playlist_t *p_playlist )
if( p_item )
{
msg_Dbg( p_playlist, "starting playback of the new playlist item" );
ResyncCurrentIndex( p_playlist, p_item );
PlayItem( p_playlist, p_item );
return;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment