diff options
-rw-r--r-- | libmpv/client.h | 12 | ||||
-rw-r--r-- | player/client.c | 6 | ||||
-rw-r--r-- | player/lua.c | 3 |
3 files changed, 20 insertions, 1 deletions
diff --git a/libmpv/client.h b/libmpv/client.h index 462ff3a9bd..a37afdbcb5 100644 --- a/libmpv/client.h +++ b/libmpv/client.h @@ -351,6 +351,18 @@ void mpv_suspend(mpv_handle *ctx); void mpv_resume(mpv_handle *ctx); /** + * Return the internal time in microseconds. This has an arbitrary start offset, + * but will never wrap or go backwards (note: the latter is probably a lie in + * the current implementation, it can go backwards on system clock changes). + * + * Note that this is always the real time, and doesn't necessarily have to do + * with playback time. For example, playback could go faster or slower due to + * playback speed, or due to playback being paused. Use the "time-pos" property + * instead to get the playback status. + */ +int64_t mpv_get_time_us(mpv_handle *ctx); + +/** * Data format for options and properties. The API functions to get/set * properties and options support multiple formats, and this enum describes * them. diff --git a/player/client.c b/player/client.c index 11fe86bdfc..eaf91c45a8 100644 --- a/player/client.c +++ b/player/client.c @@ -24,6 +24,7 @@ #include "options/m_option.h" #include "options/m_property.h" #include "osdep/threads.h" +#include "osdep/timer.h" #include "command.h" #include "core.h" @@ -992,3 +993,8 @@ void mpv_free(void *data) { talloc_free(data); } + +int64_t mpv_get_time_us(mpv_handle *ctx) +{ + return mp_time_us(); +} diff --git a/player/lua.c b/player/lua.c index dec5d22cab..edd01c0c73 100644 --- a/player/lua.c +++ b/player/lua.c @@ -722,7 +722,8 @@ static int script_get_mouse_pos(lua_State *L) static int script_get_time(lua_State *L) { - lua_pushnumber(L, mp_time_sec()); + struct script_ctx *ctx = get_ctx(L); + lua_pushnumber(L, mpv_get_time_us(ctx->client) / (double)(1000 * 1000)); return 1; } |