[vlc-devel] [PATCH 09/18] qt: allow passing media options when playing/enqueueing medialibrary items

Pierre Lamot pierre at videolabs.io
Wed Sep 23 14:27:43 CEST 2020


---
 modules/gui/qt/medialibrary/medialib.cpp | 50 ++++++++++++------------
 modules/gui/qt/medialibrary/medialib.hpp | 18 ++++-----
 modules/gui/qt/playlist/media.hpp        |  9 ++++-
 3 files changed, 41 insertions(+), 36 deletions(-)

diff --git a/modules/gui/qt/medialibrary/medialib.cpp b/modules/gui/qt/medialibrary/medialib.cpp
index f92ef54e1b..d05828889f 100644
--- a/modules/gui/qt/medialibrary/medialib.cpp
+++ b/modules/gui/qt/medialibrary/medialib.cpp
@@ -50,20 +50,20 @@ void MediaLib::openMRLFromMedia(const vlc_ml_media_t& media, bool start )
     }
 }
 
-void MediaLib::addToPlaylist(const QString& mrl)
+void MediaLib::addToPlaylist(const QString& mrl, const QStringList* options)
 {
-    vlc::playlist::Media media{ mrl, mrl };
+    vlc::playlist::Media media{ mrl, mrl, options };
     m_intf->p_sys->p_mainPlaylistController->append( {media}, false );
 }
 
-void MediaLib::addToPlaylist(const QUrl& mrl)
+void MediaLib::addToPlaylist(const QUrl& mrl, const QStringList* options)
 {
-    vlc::playlist::Media media{ mrl.toString(QUrl::None), mrl.fileName() };
+    vlc::playlist::Media media{ mrl.toString(QUrl::None), mrl.fileName(), options };
     m_intf->p_sys->p_mainPlaylistController->append( {media} , false );
 }
 
 // A specific item has been asked to be added to the playlist
-void MediaLib::addToPlaylist(const MLParentId & itemId)
+void MediaLib::addToPlaylist(const MLParentId & itemId, const QStringList* options)
 {
     //invalid item
     if (itemId.id == 0)
@@ -73,7 +73,7 @@ void MediaLib::addToPlaylist(const MLParentId & itemId)
     {
         vlc::playlist::InputItemPtr item( vlc_ml_get_input_item( m_ml, itemId.id ), false );
         if (item) {
-            QVector<vlc::playlist::Media> medias = { vlc::playlist::Media(item.get()) };
+            QVector<vlc::playlist::Media> medias = { vlc::playlist::Media(item.get(), options) };
             m_intf->p_sys->p_mainPlaylistController->append(medias, false);
         }
     }
@@ -89,37 +89,37 @@ void MediaLib::addToPlaylist(const MLParentId & itemId)
         QVector<vlc::playlist::Media> medias;
         std::transform(mediaRange.begin(), mediaRange.end(), std::back_inserter(medias), [&](vlc_ml_media_t& m) {
             vlc::playlist::InputItemPtr item(vlc_ml_get_input_item( m_ml, m.i_id ), false);
-            return vlc::playlist::Media(item.get());
+            return vlc::playlist::Media(item.get(), options);
         });
         m_intf->p_sys->p_mainPlaylistController->append(medias, false);
     }
 }
 
-void MediaLib::addToPlaylist(const QVariantList& itemIdList)
+void MediaLib::addToPlaylist(const QVariantList& itemIdList, const QStringList* options)
 {
     for (const QVariant& varValue: itemIdList)
     {
         if (varValue.canConvert<QUrl>())
         {
             auto mrl = varValue.value<QUrl>();
-            addToPlaylist(mrl);
+            addToPlaylist(mrl, options);
         }
         else if (varValue.canConvert<QString>())
         {
             auto mrl = varValue.value<QString>();
-            addToPlaylist(mrl);
+            addToPlaylist(mrl, options);
         }
         else if (varValue.canConvert<MLParentId>())
         {
             MLParentId itemId = varValue.value<MLParentId>();
-            addToPlaylist(itemId);
+            addToPlaylist(itemId, options);
         }
     }
 }
 
 // A specific item has been asked to be played,
 // so it's added to the playlist and played
-void MediaLib::addAndPlay(const MLParentId & itemId )
+void MediaLib::addAndPlay(const MLParentId & itemId, const QStringList* options )
 {
     if (itemId.id == 0)
         return;
@@ -127,7 +127,7 @@ void MediaLib::addAndPlay(const MLParentId & itemId )
     {
         vlc::playlist::InputItemPtr item(vlc_ml_get_input_item( m_ml, itemId.id ), false);
         if (item) {
-            QVector<vlc::playlist::Media> medias = { vlc::playlist::Media(item.get()) };
+            QVector<vlc::playlist::Media> medias = { vlc::playlist::Media(item.get(), options) };
             m_intf->p_sys->p_mainPlaylistController->append(medias, true);
         }
     }
@@ -143,26 +143,26 @@ void MediaLib::addAndPlay(const MLParentId & itemId )
         QVector<vlc::playlist::Media> medias;
         std::transform(mediaRange.begin(), mediaRange.end(), std::back_inserter(medias), [&](vlc_ml_media_t& m) {
             vlc::playlist::InputItemPtr item(vlc_ml_get_input_item( m_ml, m.i_id ), false);
-            return vlc::playlist::Media(item.get());
+            return vlc::playlist::Media(item.get(), options);
         });
         m_intf->p_sys->p_mainPlaylistController->append(medias, true);
     }
 }
 
-void MediaLib::addAndPlay(const QString& mrl)
+void MediaLib::addAndPlay(const QString& mrl, const QStringList* options)
 {
-    vlc::playlist::Media media{ mrl, mrl };
+    vlc::playlist::Media media{ mrl, mrl, options };
     m_intf->p_sys->p_mainPlaylistController->append( {media}, true );
 }
 
-void MediaLib::addAndPlay(const QUrl& mrl)
+void MediaLib::addAndPlay(const QUrl& mrl, const QStringList* options)
 {
-    vlc::playlist::Media media{ mrl.toString(QUrl::None), mrl.fileName() };
+    vlc::playlist::Media media{ mrl.toString(QUrl::None), mrl.fileName(), options };
     m_intf->p_sys->p_mainPlaylistController->append( {media}, true );
 }
 
 
-void MediaLib::addAndPlay(const QVariantList& itemIdList)
+void MediaLib::addAndPlay(const QVariantList& itemIdList, const QStringList* options)
 {
     bool b_start = true;
     for (const QVariant& varValue: itemIdList)
@@ -171,25 +171,25 @@ void MediaLib::addAndPlay(const QVariantList& itemIdList)
         {
             auto mrl = varValue.value<QUrl>();
             if (b_start)
-                addAndPlay(mrl);
+                addAndPlay(mrl, options);
             else
-                addToPlaylist(mrl);
+                addToPlaylist(mrl, options);
         }
         if (varValue.canConvert<QString>())
         {
             auto mrl = varValue.value<QString>();
             if (b_start)
-                addAndPlay(mrl);
+                addAndPlay(mrl, options);
             else
-                addToPlaylist(mrl);
+                addToPlaylist(mrl, options);
         }
         else if (varValue.canConvert<MLParentId>())
         {
             MLParentId itemId = varValue.value<MLParentId>();
             if (b_start)
-                addAndPlay(itemId);
+                addAndPlay(itemId, options);
             else
-                addToPlaylist(itemId);
+                addToPlaylist(itemId, options);
         } else {
             continue;
         }
diff --git a/modules/gui/qt/medialibrary/medialib.hpp b/modules/gui/qt/medialibrary/medialib.hpp
index 0db9f5ee3f..bd824092cd 100644
--- a/modules/gui/qt/medialibrary/medialib.hpp
+++ b/modules/gui/qt/medialibrary/medialib.hpp
@@ -46,15 +46,15 @@ class MediaLib : public QObject
 public:
     MediaLib(intf_thread_t* _intf, QObject* _parent = nullptr );
 
-    Q_INVOKABLE void addToPlaylist(const MLParentId &itemId);
-    Q_INVOKABLE void addToPlaylist(const QString& mrl);
-    Q_INVOKABLE void addToPlaylist(const QUrl& mrl);
-    Q_INVOKABLE void addToPlaylist(const QVariantList& itemIdList);
-
-    Q_INVOKABLE void addAndPlay(const MLParentId &itemId);
-    Q_INVOKABLE void addAndPlay(const QString& mrl);
-    Q_INVOKABLE void addAndPlay(const QUrl& mrl);
-    Q_INVOKABLE void addAndPlay(const QVariantList&itemIdList);
+    Q_INVOKABLE void addToPlaylist(const MLParentId &itemId, const QStringList* options = nullptr);
+    Q_INVOKABLE void addToPlaylist(const QString& mrl, const QStringList* options = nullptr);
+    Q_INVOKABLE void addToPlaylist(const QUrl& mrl, const QStringList* options = nullptr);
+    Q_INVOKABLE void addToPlaylist(const QVariantList& itemIdList, const QStringList* options = nullptr);
+
+    Q_INVOKABLE void addAndPlay(const MLParentId &itemId, const QStringList* options = nullptr);
+    Q_INVOKABLE void addAndPlay(const QString& mrl, const QStringList* options = nullptr);
+    Q_INVOKABLE void addAndPlay(const QUrl& mrl, const QStringList* options = nullptr);
+    Q_INVOKABLE void addAndPlay(const QVariantList&itemIdList, const QStringList* options = nullptr);
 
     Q_INVOKABLE void reload();
 
diff --git a/modules/gui/qt/playlist/media.hpp b/modules/gui/qt/playlist/media.hpp
index 7fb2867868..ef635f8556 100644
--- a/modules/gui/qt/playlist/media.hpp
+++ b/modules/gui/qt/playlist/media.hpp
@@ -36,7 +36,7 @@ using InputItemPtr = vlc_shared_data_ptr_type(input_item_t,
 class Media
 {
 public:
-    Media(input_item_t *media = nullptr)
+    Media(input_item_t *media = nullptr, const QStringList* options = nullptr)
     {
         if (media)
         {
@@ -44,10 +44,11 @@ public:
             ptr.reset(input_item_Copy(media), false);
             if (!ptr)
                 throw std::bad_alloc();
+            setMediaOptions(options);
         }
     }
 
-    Media(QString uri, QString name, QStringList* options = nullptr)
+    Media(QString uri, QString name, const QStringList* options = nullptr)
     {
         auto uUri = uri.toUtf8();
         auto uName = name.toUtf8();
@@ -56,7 +57,11 @@ public:
         ptr.reset(input_item_New(rawUri, rawName), false);
         if (!ptr)
             throw std::bad_alloc();
+        setMediaOptions(options);
+    }
 
+    void setMediaOptions(const QStringList* options = nullptr)
+    {
         if (options && options->count() > 0)
         {
             char **ppsz_options = NULL;
-- 
2.25.1



More information about the vlc-devel mailing list