1
0
mirror of https://github.com/mpv-player/mpv synced 2025-02-18 05:37:04 +00:00

player: add on_load_fail hook

This commit is contained in:
Ricardo Constantino 2018-01-02 14:20:53 +00:00
parent 97816bbef0
commit 89f81da481
No known key found for this signature in database
GPG Key ID: EFD16019AE4FF531
3 changed files with 19 additions and 5 deletions

View File

@ -790,6 +790,13 @@ The following hooks are currently defined:
``file-local-options/<option name>``. The player will wait until all
hooks are run.
``on_load_fail``
Called after after a file has been opened, but failed to. This can be
used to provide a fallback in case native demuxers failed to recognize
the file, instead of always running before the native demuxers like
``on_load``. Demux will only be retried if ``stream-open-filename``
was changed.
``on_preloaded``
Called after a file has been opened, and before tracks are selected and
decoders are created. This has some usefulness if an API users wants

View File

@ -734,12 +734,12 @@ static void transfer_playlist(struct MPContext *mpctx, struct playlist *pl)
}
}
static int process_open_hooks(struct MPContext *mpctx)
static int process_open_hooks(struct MPContext *mpctx, char *name)
{
mp_hook_run(mpctx, NULL, "on_load");
mp_hook_run(mpctx, NULL, name);
while (!mp_hook_test_completion(mpctx, "on_load")) {
while (!mp_hook_test_completion(mpctx, name)) {
mp_idle(mpctx);
if (mpctx->stop_play) {
// Can't exit immediately, the script would interfere with the
@ -1214,7 +1214,7 @@ reopen_file:
assert(mpctx->demuxer == NULL);
if (process_open_hooks(mpctx) < 0)
if (process_open_hooks(mpctx, "on_load") < 0)
goto terminate_playback;
if (opts->stream_dump && opts->stream_dump[0]) {
@ -1224,6 +1224,13 @@ reopen_file:
}
open_demux_reentrant(mpctx);
if (!mpctx->stop_play && !mpctx->demuxer &&
process_open_hooks(mpctx, "on_load_fail") >= 0 &&
strcmp(mpctx->stream_open_filename, mpctx->filename) != 0)
{
mpctx->error_playing = MPV_ERROR_LOADING_FAILED;
open_demux_reentrant(mpctx);
}
if (!mpctx->demuxer || mpctx->stop_play)
goto terminate_playback;

View File

@ -301,7 +301,7 @@ local function add_single_video(json)
end
end
mp.add_hook("on_load", 10, function ()
mp.add_hook("on_load_fail", 10, function ()
local url = mp.get_property("stream-open-filename")
local start_time = os.clock()
if (url:find("ytdl://") == 1) or