diff --git a/plugin/subminer/process.lua b/plugin/subminer/process.lua index e3119c4..f736bb6 100644 --- a/plugin/subminer/process.lua +++ b/plugin/subminer/process.lua @@ -70,8 +70,17 @@ function M.create(ctx) state.auto_play_ready_timeout = nil end + local function clear_auto_play_ready_osd_timer() + local timer = state.auto_play_ready_osd_timer + if timer and timer.kill then + timer:kill() + end + state.auto_play_ready_osd_timer = nil + end + local function disarm_auto_play_ready_gate() clear_auto_play_ready_timeout() + clear_auto_play_ready_osd_timer() state.auto_play_ready_gate_armed = false end @@ -88,10 +97,18 @@ function M.create(ctx) local function arm_auto_play_ready_gate() if state.auto_play_ready_gate_armed then clear_auto_play_ready_timeout() + clear_auto_play_ready_osd_timer() end state.auto_play_ready_gate_armed = true mp.set_property_native("pause", true) show_osd("Loading subtitle annotations...") + if type(mp.add_periodic_timer) == "function" then + state.auto_play_ready_osd_timer = mp.add_periodic_timer(2.5, function() + if state.auto_play_ready_gate_armed then + show_osd("Loading subtitle annotations...") + end + end) + end subminer_log("info", "process", "Pausing playback until SubMiner overlay/tokenization readiness signal") state.auto_play_ready_timeout = mp.add_timeout(AUTO_PLAY_READY_TIMEOUT_SECONDS, function() if not state.auto_play_ready_gate_armed then @@ -287,7 +304,7 @@ function M.create(ctx) ) end - if attempt == 1 then + if attempt == 1 and not state.auto_play_ready_gate_armed then show_osd("Starting...") end state.overlay_running = true diff --git a/plugin/subminer/state.lua b/plugin/subminer/state.lua index d4eb4de..ff227d8 100644 --- a/plugin/subminer/state.lua +++ b/plugin/subminer/state.lua @@ -29,6 +29,7 @@ function M.new() }, auto_play_ready_gate_armed = false, auto_play_ready_timeout = nil, + auto_play_ready_osd_timer = nil, } end diff --git a/scripts/test-plugin-start-gate.lua b/scripts/test-plugin-start-gate.lua index cfbc349..fb3a372 100644 --- a/scripts/test-plugin-start-gate.lua +++ b/scripts/test-plugin-start-gate.lua @@ -9,6 +9,7 @@ local function run_plugin_scenario(config) osd = {}, logs = {}, property_sets = {}, + periodic_timers = {}, } local function make_mp_stub() @@ -90,10 +91,32 @@ local function run_plugin_scenario(config) end end - function mp.add_timeout(_seconds, callback) - if callback then + function mp.add_timeout(seconds, callback) + local timeout = { + killed = false, + } + function timeout:kill() + self.killed = true + end + + local delay = tonumber(seconds) or 0 + if callback and delay < 5 then callback() end + return timeout + end + + function mp.add_periodic_timer(seconds, callback) + local timer = { + seconds = seconds, + killed = false, + callback = callback, + } + function timer:kill() + self.killed = true + end + recorded.periodic_timers[#recorded.periodic_timers + 1] = timer + return timer end function mp.register_script_message(name, fn) @@ -531,10 +554,22 @@ do has_osd_message(recorded.osd, "SubMiner: Loading subtitle annotations..."), "pause-until-ready auto-start should show loading OSD message" ) + assert_true( + not has_osd_message(recorded.osd, "SubMiner: Starting..."), + "pause-until-ready auto-start should avoid replacing loading OSD with generic starting OSD" + ) assert_true( has_osd_message(recorded.osd, "SubMiner: Subtitle annotations loaded"), "autoplay-ready should show loaded OSD message" ) + assert_true( + #recorded.periodic_timers == 1, + "pause-until-ready auto-start should create periodic loading OSD refresher" + ) + assert_true( + recorded.periodic_timers[1].killed == true, + "autoplay-ready should stop periodic loading OSD refresher" + ) end do