Time-out based on stream position
Quits mpv when a stream’s position hasn’t changed in more than 5 seconds, or when cache is longer than 30s (and thus the stream is significantly behind real-time).
Useful for long-term streaming playback that’s resilient to temporary network drop-outs, etc. As in: while true; do mpv --script pos-timeout.lua http://example.com/stream.mp3; sleep 1; done
last_pos = ""
mp.add_periodic_timer(5, function()
stream_pos = mp.get_property("stream-pos")
if (stream_pos == last_pos) then
print("Detected a hang-up for more than 5s, quitting...")
mp.command("quit")
end
last_pos = stream_pos
if (tonumber(mp.get_property("demuxer-cache-duration")) > 30) then
print("Detected cache lag of more than 30s, quitting...")
mp.command("quit")
end
end)