[vlc-devel] [PATCH 2/3] libvlc: add the title in title_selection_changed event

Thomas Guillem thomas at gllm.fr
Tue Apr 28 13:46:45 CEST 2020


Because calling libvlc_media_player_get_full_title_descriptions(), getting the
title via the index and releasing the whole list is not convenient to get the
info about the selected title.
---
 include/vlc/libvlc_events.h | 8 +++++++-
 lib/media_player.c          | 9 ++++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/include/vlc/libvlc_events.h b/include/vlc/libvlc_events.h
index c901c8079d..167e4f00c1 100644
--- a/include/vlc/libvlc_events.h
+++ b/include/vlc/libvlc_events.h
@@ -34,6 +34,7 @@ extern "C" {
 # endif
 
 typedef struct libvlc_renderer_item_t libvlc_renderer_item_t;
+typedef struct libvlc_title_description_t libvlc_title_description_t;
 
 /**
  * \ingroup libvlc_event
@@ -118,6 +119,10 @@ enum libvlc_event_e {
     libvlc_MediaPlayerUnmuted,
     libvlc_MediaPlayerAudioVolume,
     libvlc_MediaPlayerAudioDevice,
+    /**
+     * The title selection changed, cf media_player_title_selection_changed in
+     * \ref libvlc_event_t.u
+     */
     libvlc_MediaPlayerTitleSelectionChanged,
     libvlc_MediaPlayerChapterChanged,
 
@@ -266,7 +271,8 @@ typedef struct libvlc_event_t
         } media_player_time_changed;
         struct
         {
-            int new_title;
+            const libvlc_title_description_t *title;
+            int index;
         } media_player_title_selection_changed;
         struct
         {
diff --git a/lib/media_player.c b/lib/media_player.c
index 42d20537c6..271c244740 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -342,9 +342,16 @@ on_title_selection_changed(vlc_player_t *player,
 
     libvlc_media_player_t *mp = data;
 
+    const libvlc_title_description_t libtitle = {
+        .i_duration = MS_FROM_VLC_TICK(new_title->length),
+        .psz_name = (char *) new_title->name,
+        .i_flags = new_title->flags,
+    };
+
     libvlc_event_t event;
     event.type = libvlc_MediaPlayerTitleSelectionChanged;
-    event.u.media_player_title_selection_changed.new_title = new_idx;
+    event.u.media_player_title_selection_changed.title = &libtitle;
+    event.u.media_player_title_selection_changed.index = new_idx;
 
     libvlc_event_send(&mp->event_manager, &event);
 }
-- 
2.20.1



More information about the vlc-devel mailing list