[vlc-devel] [PATCH 2/2] libvlc: support setting seek mode

Zhao Zhili quinkblack at foxmail.com
Tue Jun 19 13:35:45 CEST 2018


---
 include/vlc/libvlc_media_player.h | 10 ++++++++--
 lib/media_player.c                | 22 ++++++++++++++--------
 2 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
index 9ef1dde..87d3368 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -785,9 +785,12 @@ LIBVLC_API libvlc_time_t libvlc_media_player_get_time( libvlc_media_player_t *p_
  * Not all formats and protocols support this.
  *
  * \param p_mi the Media Player
+ * \param b_fast prefer fast seeking or precise seeking
  * \param i_time the movie time (in ms).
+ * \return 0 on success, -1 on error
  */
-LIBVLC_API void libvlc_media_player_set_time( libvlc_media_player_t *p_mi, libvlc_time_t i_time );
+LIBVLC_API int libvlc_media_player_set_time( libvlc_media_player_t *p_mi,
+                                             libvlc_time_t i_time, bool b_fast );
 
 /**
  * Get movie position as percentage between 0.0 and 1.0.
@@ -803,9 +806,12 @@ LIBVLC_API float libvlc_media_player_get_position( libvlc_media_player_t *p_mi )
  * This might not work depending on the underlying input format and protocol.
  *
  * \param p_mi the Media Player
+ * \param b_fast prefer fast seeking or precise seeking
  * \param f_pos the position
+ * \return 0 on success, -1 on error
  */
-LIBVLC_API void libvlc_media_player_set_position( libvlc_media_player_t *p_mi, float f_pos );
+LIBVLC_API int libvlc_media_player_set_position( libvlc_media_player_t *p_mi,
+                                                 float f_pos, bool b_fast );
 
 /**
  * Set movie chapter (if applicable).
diff --git a/lib/media_player.c b/lib/media_player.c
index cd9d3ee..0bbf84e 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -1325,30 +1325,36 @@ libvlc_time_t libvlc_media_player_get_time( libvlc_media_player_t *p_mi )
     return i_time;
 }
 
-void libvlc_media_player_set_time( libvlc_media_player_t *p_mi,
-                                   libvlc_time_t i_time )
+int libvlc_media_player_set_time( libvlc_media_player_t *p_mi,
+                                   libvlc_time_t i_time, bool b_fast )
 {
+    int ret = -1;
     input_thread_t *p_input_thread;
 
     p_input_thread = libvlc_get_input_thread ( p_mi );
     if( !p_input_thread )
-        return;
+        return -1;
 
-    var_SetInteger( p_input_thread, "time", to_mtime(i_time) );
+    if( vlc_SetTime( p_input_thread, to_mtime(i_time), b_fast ) == VLC_SUCCESS )
+        ret = 0;
     vlc_object_release( p_input_thread );
+    return ret;
 }
 
-void libvlc_media_player_set_position( libvlc_media_player_t *p_mi,
-                                       float position )
+int libvlc_media_player_set_position( libvlc_media_player_t *p_mi,
+                                       float position, bool b_fast )
 {
+    int ret = -1;
     input_thread_t *p_input_thread;
 
     p_input_thread = libvlc_get_input_thread ( p_mi );
     if( !p_input_thread )
-        return;
+        return -1;
 
-    var_SetFloat( p_input_thread, "position", position );
+    if( vlc_SetPosition( p_input_thread, position, b_fast ) == VLC_SUCCESS )
+        ret = 0;
     vlc_object_release( p_input_thread );
+    return ret;
 }
 
 float libvlc_media_player_get_position( libvlc_media_player_t *p_mi )
-- 
2.9.5





More information about the vlc-devel mailing list