Replies: 5 comments 17 replies
-
我都记不得为什么添加 demuxer-hysteresis-secs 了,看了下 commit 历史才想起来。当时 mpv 对 watch-later-options 进行了破坏性的更新,然后脑抽了一下用临近添加的新属性 demuxer-hysteresis-secs 是否存在来进行兼容性判断了,实际应该只要判断 watch-later-options 参数就行了,在此更新之前 start 值无效
“播放器暂停 pause,触发 save_if_pause 函数”,这个应该只在 keep-open 不为 no 和 keep-open-pause=yes 时才会触发?我不使用 keep-open 而是 idle 所以没注意到这点 |
Beta Was this translation helpful? Give feedback.
-
还有一个地方,我没搞清楚: 为什么文件结束时需要监控2个属性/事件,感觉这2个应该会都触发?但实际上只见到前者的log |
Beta Was this translation helpful? Give feedback.
-
花时间测试了一下eof-reached属性、end-file事件,还有on_unload的hook eof-reached属性用于判断文件播放到底是最及时、管用的,文件只要播放到底就立刻变true,加载文件前变nil,加载完文件变成false end-file事件:在切换文件过程中,卸载文件时才触发这个事件,文件播放到底时还不会触发。 另外关闭播放器时,end-file的reason是quit,然后是shutdown事件。 on_unload的hook在end-file前,此时path属性还没清除,适合执行操作 |
Beta Was this translation helpful? Give feedback.
-
完全重写了一个,去掉了定时,不过再加上去也很简单。
local msg = require("mp.msg")
local path = nil -- only set after file success load, reset to nil when file unload.
local function reset()
path = nil
end
-- set vars when file success load
local function init()
path = mp.get_property("path")
end
-- save watch-later-config when file unloading
local function save_or_delete()
local eof = mp.get_property_bool("eof-reached")
local percent_pos = mp.get_property_number("percent-pos")
if path ~= nil then
if eof or percent_pos==0 then
msg.debug("deleting state: percent_pos=0 or eof")
mp.commandv("delete-watch-later-config", path)
elseif mp.get_property_bool("save-position-on-quit") then
msg.debug("saving state")
mp.commandv("write-watch-later-config")
end
reset()
end
end
mp.register_event("file-loaded", init)
mp.add_hook("on_unload", 50, save_or_delete) -- after mpv saving state 我自测感觉没啥问题,可以作为基础框架往上加脚本全局开关、当前文件临时关闭的功能 |
Beta Was this translation helpful? Give feedback.
-
还有一个小细节,可能是keep-open=always或者最后一个文件才会有的问题:播放完毕,自动暂停时, percent-pos可能不是100,而是99.xx的一个接近100的数。同理,暂停时的时间也不会正好等于文件的时长,而是无限接近的值… 脚本的设置里percent_pos设为100可能会遇到这样的特殊情况不起作用,不过eof属性是足够作为判据,不需要再用percent_pos=100了 |
Beta Was this translation helpful? Give feedback.
-
mpv-config/scripts/auto-save-state.lua
Line 41 in 7d1cecc
我不太清楚为什么要判断demuxer-hysteresis-secs是否存在,但还是先只分析这一行的判断条件
demuxer-hysteresis-secs
默认值是0,你可能希望是默认值0的时候,if会得到false的结果。然而实际上它在默认值时,demuxer_secs = mp.get_property("demuxer-hysteresis-secs")
还是得到truemp.get_property("demuxer-hysteresis-secs")
得到的是字符串0.0000,需要用mp.get_property_native("demuxer-hysteresis-secs")
,并且用demuxer_secs~=0
来作判断mp.commandv("delete-watch-later-config", path)
,即不保存watch-later。实际上:先触发eof_reached函数,删除watch-later;然后播放器暂停pause,触发save_if_pause函数,又保存了watch-later。
这相当于watch-later还是保存了,eof_reached函数是无效的
我建议增加一个can_save变量
Beta Was this translation helpful? Give feedback.
All reactions