Skip to content

Commit

Permalink
client: add MPV_EVENT_INITIALIZED
Browse files Browse the repository at this point in the history
This may be useful for waiting until all scripts have finished loading.
Use with caution, as scripts shouldn't perform too many tasks during
initialization or afterward. Instead, they should wait to be triggered
by property or event changes.
  • Loading branch information
kasper93 committed Oct 14, 2024
1 parent 228f386 commit e4038b0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions DOCS/client-api-changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ API changes

::

--- mpv 0.40.0 ---
2.5 - add MPV_EVENT_INITIALIZED event
--- mpv 0.39.0 ---
2.4 - mpv_render_param with the MPV_RENDER_PARAM_ICC_PROFILE argument no
longer has incorrect assumptions about memory allocation and can be
Expand Down
4 changes: 4 additions & 0 deletions DOCS/man/input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,10 @@ This list uses the event name field value, and the C API symbol in brackets:
``data``
The new value of the property.

``initialized`` (``MPV_EVENT_INITIALIZED``)
Triggered after initialization is complete, including all scripts.
mpv is proceeding to play the file.

The following events also happen, but are deprecated: ``idle``, ``tick``
Use ``mpv_observe_property()`` (Lua: ``mp.observe_property()``) instead.

Expand Down
5 changes: 5 additions & 0 deletions libmpv/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,11 @@ typedef enum mpv_event_id {
* See also mpv_event and mpv_event_hook.
*/
MPV_EVENT_HOOK = 25,
/**
* Triggered after initialization is complete, including all scripts.
* mpv is proceeding to play the file.
*/
MPV_EVENT_INITIALIZED = 26,
// Internal note: adjust INTERNAL_EVENT_BASE when adding new events.
} mpv_event_id;

Expand Down
1 change: 1 addition & 0 deletions player/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -2114,6 +2114,7 @@ static const char *const event_table[] = {
[MPV_EVENT_PROPERTY_CHANGE] = "property-change",
[MPV_EVENT_QUEUE_OVERFLOW] = "event-queue-overflow",
[MPV_EVENT_HOOK] = "hook",
[MPV_EVENT_INITIALIZED] = "initialized",
};

const char *mpv_event_name(mpv_event_id event)
Expand Down
1 change: 1 addition & 0 deletions player/loadfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -2015,6 +2015,7 @@ void mp_play_files(struct MPContext *mpctx)
}
// After above is finished; but even if it's skipped.
mp_msg_set_early_logging(mpctx->global, false);
mp_notify(mpctx, MPV_EVENT_INITIALIZED, NULL);

prepare_playlist(mpctx, mpctx->playlist);

Expand Down

0 comments on commit e4038b0

Please sign in to comment.