[vlc-commits] cli: implement relative seek (fixes #24987)
Rémi Denis-Courmont
git at videolan.org
Sat Oct 17 20:36:13 CEST 2020
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Oct 17 21:15:36 2020 +0300| [54e0eb7bd98eac6876bf2235ee7c42b0d9edbea9] | committer: Rémi Denis-Courmont
cli: implement relative seek (fixes #24987)
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=54e0eb7bd98eac6876bf2235ee7c42b0d9edbea9
---
modules/control/cli/player.c | 27 ++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)
diff --git a/modules/control/cli/player.c b/modules/control/cli/player.c
index 2696157e0c..ec3392863b 100644
--- a/modules/control/cli/player.c
+++ b/modules/control/cli/player.c
@@ -251,17 +251,30 @@ static void PlayerSeek(intf_thread_t *intf, const char *const *args,
{
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
- vlc_player_Lock(player);
- if (count > 1 && args[1][strlen(args[1]) - 1] == '%' )
+ if (count != 2)
{
- float f = atof(args[1]) / 100.0;
- vlc_player_SetPosition(player, f);
+ msg_print(intf, "%s expects one parameter", args[0]);
+ return;
}
- else
+
+ char *end;
+ double value = strtod(args[1], &end);
+ bool relative = args[1][0] == '-' || args[1][0] == '+';
+ bool pct = *end == '%';
+
+ vlc_player_Lock(player);
+ if (relative)
{
- int t = atoi(args[1]);
- vlc_player_SetTime(player, vlc_tick_from_sec(t));
+ if (pct)
+ value += vlc_player_GetPosition(player) * 100.;
+ else
+ value += secf_from_vlc_tick(vlc_player_GetTime(player));
}
+
+ if (pct)
+ vlc_player_SetPosition(player, value / 100.);
+ else
+ vlc_player_SetTime(player, vlc_tick_from_sec(value));
vlc_player_Unlock(player);
}
More information about the vlc-commits
mailing list