diff --git a/include/vlc_media_library.h b/include/vlc_media_library.h index fde638692d75b5f36bf6fc929058e403252a1e97..38cf37f895ba448d914cc6eafbe5ea755486b061 100644 --- a/include/vlc_media_library.h +++ b/include/vlc_media_library.h @@ -498,6 +498,11 @@ enum vlc_ml_control VLC_ML_MEDIA_REMOVE_BOOKMARK, /**< arg1: media id; arg2: int64_t */ VLC_ML_MEDIA_REMOVE_ALL_BOOKMARKS, /**< arg1: media id */ VLC_ML_MEDIA_UPDATE_BOOKMARK, /**< arg1: media id; arg2: int64_t; arg3: const char*; arg4: const char* */ + + /* Playlist management */ + VLC_ML_PLAYLIST_CREATE, /**< arg1: const char*; arg2(out): vlc_ml_playlist_t**; can fail */ + VLC_ML_PLAYLIST_DELETE, /**< arg1: playlist id; can fail */ + VLC_ML_PLAYLIST_APPEND /**< arg1: playlist id; arg2: media id; can fail */ }; /** @@ -1045,6 +1050,35 @@ vlc_ml_media_remove_all_bookmarks( vlc_medialibrary_t* p_ml, int64_t i_media_id return vlc_ml_control( p_ml, VLC_ML_MEDIA_REMOVE_ALL_BOOKMARKS, i_media_id ); } +static inline vlc_ml_playlist_t* +vlc_ml_playlist_create( vlc_medialibrary_t * p_ml, const char * name) +{ + assert( p_ml != NULL ); + + vlc_ml_playlist_t* result; + + if (vlc_ml_control( p_ml, VLC_ML_PLAYLIST_CREATE, name, &result ) != VLC_SUCCESS ) + return NULL; + + return result; +} + +static inline int +vlc_ml_playlist_delete( vlc_medialibrary_t * p_ml, int64_t i_playlist_id ) +{ + assert( p_ml != NULL ); + + return vlc_ml_control( p_ml, VLC_ML_PLAYLIST_DELETE, i_playlist_id ); +} + +static inline int +vlc_ml_playlist_append( vlc_medialibrary_t * p_ml, int64_t i_playlist_id, int64_t i_media_id ) +{ + assert( p_ml != NULL ); + + return vlc_ml_control( p_ml, VLC_ML_PLAYLIST_APPEND, i_playlist_id, i_media_id ); +} + static inline vlc_ml_media_t* vlc_ml_get_media( vlc_medialibrary_t* p_ml, int64_t i_media_id ) { return (vlc_ml_media_t*)vlc_ml_get( p_ml, VLC_ML_GET_MEDIA, i_media_id ); diff --git a/modules/misc/medialibrary/medialibrary.cpp b/modules/misc/medialibrary/medialibrary.cpp index 6c4583f66e38e9a592a04ee9c22be080eb16b7c8..1df3c5947377a6a26617f7088eb1db3725c5801b 100644 --- a/modules/misc/medialibrary/medialibrary.cpp +++ b/modules/misc/medialibrary/medialibrary.cpp @@ -623,6 +623,31 @@ int MediaLibrary::Control( int query, va_list args ) case VLC_ML_MEDIA_REMOVE_ALL_BOOKMARKS: case VLC_ML_MEDIA_UPDATE_BOOKMARK: return controlMedia( query, args ); + case VLC_ML_PLAYLIST_CREATE: + { + auto name = va_arg( args, const char * ); + auto playlist = m_ml->createPlaylist( name ); + if ( playlist == nullptr ) + return VLC_EGENERIC; + auto result = va_arg( args, vlc_ml_playlist_t** ); + *result = CreateAndConvert<vlc_ml_playlist_t>( playlist.get() ); + return VLC_SUCCESS; + } + case VLC_ML_PLAYLIST_DELETE: + { + if ( m_ml->deletePlaylist( va_arg( args, int64_t ) ) == false ) + return VLC_EGENERIC; + return VLC_SUCCESS; + } + case VLC_ML_PLAYLIST_APPEND: + { + auto playlist = m_ml->playlist( va_arg( args, int64_t ) ); + if ( playlist == nullptr ) + return VLC_EGENERIC; + if ( playlist->append(va_arg( args, int64_t )) == false ) + return VLC_EGENERIC; + return VLC_SUCCESS; + } default: return VLC_EGENERIC; }