[vlc-commits] playlist: preserve first item when enabling random mode

Edward Wang git at videolan.org
Sun May 27 08:43:05 CEST 2012


vlc | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Fri May 25 23:48:19 2012 -0400| [a5a428df27a4752a79c503bbe14ce3d67c76b777] | committer: Jean-Baptiste Kempf

playlist: preserve first item when enabling random mode

Close #4472

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a5a428df27a4752a79c503bbe14ce3d67c76b777
---

 src/playlist/engine.c            |   17 +++++++++++++++--
 src/playlist/playlist_internal.h |    2 ++
 src/playlist/thread.c            |   12 ++++++++++--
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/src/playlist/engine.c b/src/playlist/engine.c
index e22a1b2..15b0d26 100644
--- a/src/playlist/engine.c
+++ b/src/playlist/engine.c
@@ -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;
diff --git a/src/playlist/playlist_internal.h b/src/playlist/playlist_internal.h
index 3812edc..c1a006a 100644
--- a/src/playlist/playlist_internal.h
+++ b/src/playlist/playlist_internal.h
@@ -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 );
 
 /**
  * @}
diff --git a/src/playlist/thread.c b/src/playlist/thread.c
index af4d886..5ccfa1e 100644
--- a/src/playlist/thread.c
+++ b/src/playlist/thread.c
@@ -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;
     }



More information about the vlc-commits mailing list