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

Edward Wang git at videolan.org
Sun Jun 3 23:37:50 CEST 2012


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

playlist: preserve first item when enabling random mode

Close #4472

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
(cherry picked from commit a5a428df27a4752a79c503bbe14ce3d67c76b777)

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

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

 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 01d887a..1599ed0 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 ba1bfb0..75ac585 100644
--- a/src/playlist/playlist_internal.h
+++ b/src/playlist/playlist_internal.h
@@ -148,6 +148,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 29cb89e..21c740a 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);
@@ -543,6 +550,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