[vlc-devel] [PATCH 4/7] player: Add a on_playback_restore_queried callback

Hugo Beauzée-Luyssen hugo at beauzee.fr
Tue Jan 21 16:18:01 CET 2020


And use it to ask the user if they want to resume the playback position
when a last position is known by the media library
---
 include/vlc_player.h                        | 16 ++++++++++++++++
 modules/gui/qt/player/player_controller.cpp |  3 ++-
 modules/gui/skins2/src/vlcproc.cpp          |  1 +
 src/player/input.c                          |  1 +
 src/player/medialib.c                       |  3 +++
 src/player/player.c                         |  5 +++++
 6 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/include/vlc_player.h b/include/vlc_player.h
index 52dc703609..8da6111294 100644
--- a/include/vlc_player.h
+++ b/include/vlc_player.h
@@ -3032,6 +3032,22 @@ struct vlc_player_cbs
      */
     void (*on_cork_changed)(vlc_player_t *player, unsigned cork_count,
                             void *data);
+
+    /**
+     * Called to query the user about restoring the previous playback position
+     *
+     * If this callback isn't provided, the user won't be asked to restore
+     * the previous playback position, effectively causing
+     * VLC_PLAYER_RESTORE_PLAYBACK_POS_ASK to be handled as
+     * VLC_PLAYER_RESTORE_PLAYBACK_POS_NEVER
+     *
+     * The implementation can react to this callback by calling
+     * vlc_player_RestorePlaybackPos(), or by discarding the event.
+     *
+     * @param player locked player instance
+     * @param data opaque pointer set by vlc_player_AddListener()
+     */
+    void (*on_playback_restore_queried)(vlc_player_t *player, void *data);
 };
 
 /**
diff --git a/modules/gui/qt/player/player_controller.cpp b/modules/gui/qt/player/player_controller.cpp
index 3dfb375724..129d4c1429 100644
--- a/modules/gui/qt/player/player_controller.cpp
+++ b/modules/gui/qt/player/player_controller.cpp
@@ -949,7 +949,8 @@ static const struct vlc_player_cbs player_cbs = {
     on_player_media_epg_changed,
     on_player_subitems_changed,
     on_player_vout_changed,
-    on_player_corks_changed
+    on_player_corks_changed,
+    nullptr
 };
 
 static const struct vlc_player_vout_cbs player_vout_cbs = {
diff --git a/modules/gui/skins2/src/vlcproc.cpp b/modules/gui/skins2/src/vlcproc.cpp
index 495d32e79d..ed8cbe846d 100644
--- a/modules/gui/skins2/src/vlcproc.cpp
+++ b/modules/gui/skins2/src/vlcproc.cpp
@@ -413,6 +413,7 @@ VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ),
     NULL, //on_player_subitems_changed,
     on_player_vout_changed,
     NULL, //on_player_corks_changed
+    NULL, //on_playback_restore_queried
     };
 
     static const struct vlc_player_vout_cbs player_vout_cbs = {
diff --git a/src/player/input.c b/src/player/input.c
index 69328924b9..37a235664b 100644
--- a/src/player/input.c
+++ b/src/player/input.c
@@ -884,6 +884,7 @@ vlc_player_input_New(vlc_player_t *player, input_item_t *item)
     input->ml.states.progress = -1.f;
     input->ml.restore = VLC_RESTOREPOINT_NONE;
     input->ml.restore_states = false;
+    input->ml.delay_restore = false;
 
     input->thread = input_Create(player, input_thread_Events, input, item,
                                  player->resource, player->renderer);
diff --git a/src/player/medialib.c b/src/player/medialib.c
index a887bb5a34..d9b70fac55 100644
--- a/src/player/medialib.c
+++ b/src/player/medialib.c
@@ -59,6 +59,9 @@ vlc_player_input_RestoreMlStates(struct vlc_player_input* input, bool force_pos)
             input->ml.states.current_title == -1 &&
             input->ml.states.progress > .0f)
         input_SetPosition(input->thread, input->ml.states.progress, false);
+    else if (restore_pos == VLC_PLAYER_RESTORE_PLAYBACK_POS_ASK &&
+             input->ml.states.progress > .0f)
+        input->ml.delay_restore = true;
 
     if (!restore_states)
         return;
diff --git a/src/player/player.c b/src/player/player.c
index 85cca86e0b..89c16caf6a 100644
--- a/src/player/player.c
+++ b/src/player/player.c
@@ -100,6 +100,11 @@ vlc_player_OpenNextMedia(vlc_player_t *player)
         }
     }
     vlc_player_SendEvent(player, on_current_media_changed, player->media);
+    if (player->input && player->input->ml.delay_restore)
+    {
+        vlc_player_SendEvent(player, on_playback_restore_queried);
+        player->input->ml.delay_restore = false;
+    }
     return ret;
 }
 
-- 
2.20.1



More information about the vlc-devel mailing list