[vlc-devel] [PATCH] playlist: Media Library automatic item removal
Aleksandr Pasechnik
al at megamicron.net
Mon May 25 13:52:27 CEST 2015
Added a setting that automatically removes the last played item from the
playlist once the next item starts playing. This setting only effects the Media
Library portion of the playlist. When the setting is enabled, the Media Library
acts as a media queue, allowing the user to add items to it however they wish,
and have those items automatically removed when they are finished with them.
Items are not removed if the user manually selects an item to play from the
playlist.
---
src/libvlc-module.c | 6 ++++++
src/playlist/playlist_internal.h | 3 +++
src/playlist/thread.c | 18 ++++++++++++++++++
3 files changed, 27 insertions(+)
diff --git a/src/libvlc-module.c b/src/libvlc-module.c
index 65a9269..d6d0dcb 100644
--- a/src/libvlc-module.c
+++ b/src/libvlc-module.c
@@ -1140,6 +1140,11 @@ static const char *const ppsz_prefres[] = {
"The media library is automatically saved and reloaded each time you " \
"start VLC." )
+#define PRP_TEXT N_("Remove Media Library items after playing")
+#define PRP_LONGTEXT N_( \
+ "Use the Media Library as a media queue, automatically removing " \
+ "items after they are played." )
+
#define PLTREE_TEXT N_("Display playlist tree")
#define PLTREE_LONGTEXT N_( \
"The playlist can use a tree to categorize some items, like the " \
@@ -2005,6 +2010,7 @@ vlc_module_begin ()
PLAYLISTENQUEUE_LONGTEXT, true )
#endif
add_bool( "media-library", 0, ML_TEXT, ML_LONGTEXT, false )
+ add_bool( "playlist-remove-played", 0, PRP_TEXT, PRP_LONGTEXT, false );
add_bool( "playlist-tree", 0, PLTREE_TEXT, PLTREE_LONGTEXT, false )
add_string( "open", "", OPEN_TEXT, OPEN_LONGTEXT, false )
diff --git a/src/playlist/playlist_internal.h b/src/playlist/playlist_internal.h
index 20f0343..0c51828 100644
--- a/src/playlist/playlist_internal.h
+++ b/src/playlist/playlist_internal.h
@@ -65,6 +65,9 @@ typedef struct playlist_private_t
playlist_item_t * p_node; /**< Current node to play from */
} status;
+ playlist_item_t *p_previous_item; /* The previously played item IFF
+ * the items are changing automatically */
+
struct {
/* Request. Use this to give orders to the playlist main loop */
playlist_item_t * p_node; /**< requested node to play from */
diff --git a/src/playlist/thread.c b/src/playlist/thread.c
index 178c5cc..d55af83 100644
--- a/src/playlist/thread.c
+++ b/src/playlist/thread.c
@@ -240,6 +240,16 @@ static bool PlayItem( playlist_t *p_playlist, playlist_item_t *p_item )
var_SetAddress( p_playlist, "input-current", p_input_thread );
PL_LOCK;
+
+ if( strcmp( PLI_NAME( p_sys->status.p_node ), "Media Library" ) == 0 )
+ {
+ if( p_sys->p_previous_item != NULL && var_InheritBool( p_playlist, "playlist-remove-played" ) )
+ {
+ msg_Dbg( p_playlist, "will automatically remove previous item from Media Library" );
+ int i_ret = playlist_DeleteFromInput( p_playlist, p_sys->p_previous_item->p_input, true );
+ }
+ }
+
return p_input_thread != NULL;
}
@@ -259,6 +269,9 @@ static playlist_item_t *NextItem( playlist_t *p_playlist )
/* Clear the request */
p_sys->request.b_request = false;
+ /* Clear the previous item */
+ p_sys->p_previous_item = NULL;
+
/* Handle quickly a few special cases */
/* No items to play */
if( p_playlist->items.i_size == 0 )
@@ -421,10 +434,15 @@ static playlist_item_t *NextItem( playlist_t *p_playlist )
if ( p_playlist->current.i_size == 0 )
return NULL;
+ p_sys->p_previous_item = get_current_status_item( p_playlist );
+
p_new = ARRAY_VAL( p_playlist->current, p_playlist->i_current_index );
/* The new item can't be autoselected */
if( p_new != NULL && p_new->i_flags & PLAYLIST_SKIP_FLAG )
+ {
+ p_sys->p_previous_item = NULL;
return NULL;
+ }
}
return p_new;
}
--
2.4.1
More information about the vlc-devel
mailing list