From e077ccd68df9b59949e7669b136e99bca7a0918e Mon Sep 17 00:00:00 2001 From: Thomas Guillem Date: Fri, 17 May 2024 15:11:57 +0200 Subject: [PATCH] lib: media_player: add jump_time --- include/vlc/libvlc_media_player.h | 21 +++++++++++++++++++-- lib/libvlc.sym | 1 + lib/media_player.c | 19 ++++++++++++++++--- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h index 4812e12cbc..e92adcf27c 100644 --- a/include/vlc/libvlc_media_player.h +++ b/include/vlc/libvlc_media_player.h @@ -1227,17 +1227,34 @@ LIBVLC_API libvlc_time_t libvlc_media_player_get_length( libvlc_media_player_t * LIBVLC_API libvlc_time_t libvlc_media_player_get_time( libvlc_media_player_t *p_mi ); /** - * Set the movie time (in ms). This has no effect if no media is being played. + * Set the movie time (in ms). + * + * This has no effect if no media is being played. * 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). + * \param b_fast prefer fast seeking or precise seeking * \return 0 on success, -1 on error */ LIBVLC_API int libvlc_media_player_set_time( libvlc_media_player_t *p_mi, libvlc_time_t i_time, bool b_fast ); +/** + * Jump the movie time (in ms). + * + * This will trigger a precise and relative seek (from the current time). + * This has no effect if no media is being played. + * Not all formats and protocols support this. + * + * \param p_mi the Media Player + * \param i_time the movie time (in ms). + * \return 0 on success, -1 on error + * \version LibVLC 4.0.0 and later. + */ +LIBVLC_API int libvlc_media_player_jump_time( libvlc_media_player_t *p_mi, + libvlc_time_t i_time ); + /** * Get movie position as percentage between 0.0 and 1.0. * diff --git a/lib/libvlc.sym b/lib/libvlc.sym index 5a174a8309..4e29fb6385 100644 --- a/lib/libvlc.sym +++ b/lib/libvlc.sym @@ -174,6 +174,7 @@ libvlc_media_player_set_rate libvlc_media_player_set_renderer libvlc_media_player_set_role libvlc_media_player_set_time +libvlc_media_player_jump_time libvlc_media_player_set_title libvlc_media_player_set_xwindow libvlc_media_player_stop_async diff --git a/lib/media_player.c b/lib/media_player.c index f1650a32ff..38fd4b9553 100644 --- a/lib/media_player.c +++ b/lib/media_player.c @@ -1342,8 +1342,9 @@ libvlc_time_t libvlc_media_player_get_time( libvlc_media_player_t *p_mi ) return i_time; } -int libvlc_media_player_set_time( libvlc_media_player_t *p_mi, - libvlc_time_t i_time, bool b_fast ) +static int +set_time( libvlc_media_player_t *p_mi, libvlc_time_t i_time, bool b_fast, + enum vlc_player_whence whence ) { vlc_tick_t tick = vlc_tick_from_libvlc_time(i_time); @@ -1352,7 +1353,7 @@ int libvlc_media_player_set_time( libvlc_media_player_t *p_mi, enum vlc_player_seek_speed speed = b_fast ? VLC_PLAYER_SEEK_FAST : VLC_PLAYER_SEEK_PRECISE; - vlc_player_SeekByTime(player, tick, speed, VLC_PLAYER_WHENCE_ABSOLUTE); + vlc_player_SeekByTime(player, tick, speed, whence); vlc_player_Unlock(player); @@ -1360,6 +1361,18 @@ int libvlc_media_player_set_time( libvlc_media_player_t *p_mi, return 0; } +int libvlc_media_player_set_time( libvlc_media_player_t *p_mi, + libvlc_time_t i_time, bool b_fast ) +{ + return set_time( p_mi, i_time, b_fast, VLC_PLAYER_WHENCE_ABSOLUTE ); +} + +int libvlc_media_player_jump_time( libvlc_media_player_t *p_mi, + libvlc_time_t i_time ) +{ + return set_time( p_mi, i_time, false, VLC_PLAYER_WHENCE_RELATIVE ); +} + int libvlc_media_player_set_position( libvlc_media_player_t *p_mi, double position, bool b_fast ) {