[Share Experiences] 用mpv做个复读机——mpv的lua扩展
Tofloor
poster avatar
wils
deepin
4 hours ago
Author

这里用的灵犀claw,用其他agent也一样

就是让AI写个mpv的lua扩展,按A记录位置,按B循环播放,按C退出循环

1.png

得到的lua脚本如下

-- mpv_repeater.lua
-- 复读机:按 A 标记起点,按 B 标记终点,在 A↔B 之间循环播放
-- 按 C 取消所有标记,停止循环
--
-- 使用方法:将本文件放入 mpv 的 scripts 目录即可自动加载

local mp = require("mp")

local mark_a = nil  -- 起点位置(秒)
local mark_b = nil  -- 终点位置(秒)
local looping = false  -- 是否处于循环模式

-- 检查当前位置是否已到达/超过标记 B,若是则跳回标记 A
local function on_time_pos_change(name, val)
    if not looping or val == nil then
        return
    end
    -- 确保两个标记都已设置,且当前位置 >= 标记 B
    if mark_a ~= nil and mark_b ~= nil and val >= mark_b then
        mp.set_property_number("time-pos", mark_a)
    end
end

-- 注册 time-pos 属性观察,实时检测播放位置
mp.observe_property("time-pos", "number", on_time_pos_change)

-- ====== 按键绑定 ======

-- 按 A:标记起点(位置 1)
mp.add_key_binding("a", "repeater-mark-a", function()
    local pos = mp.get_property_number("time-pos")
    if pos == nil then
        mp.osd_message("复读机:无法获取当前播放位置", 2)
        return
    end
    mark_a = pos
    if mark_b ~= nil then
        looping = true
        mp.osd_message(string.format("复读机:已标记 A=%.1fs  B=%.1fs  开始循环", mark_a, mark_b), 3)
    else
        mp.osd_message(string.format("复读机:标记起点 A=%.1fs(再按 B 设置终点)", mark_a), 2)
    end
end)

-- 按 B:标记终点(位置 2)
mp.add_key_binding("b", "repeater-mark-b", function()
    local pos = mp.get_property_number("time-pos")
    if pos == nil then
        mp.osd_message("复读机:无法获取当前播放位置", 2)
        return
    end
    mark_b = pos
    if mark_a ~= nil then
        looping = true
        mp.osd_message(string.format("复读机:已标记 A=%.1fs  B=%.1fs  开始循环", mark_a, mark_b), 3)
    else
        mp.osd_message(string.format("复读机:标记终点 B=%.1fs(再按 A 设置起点)", mark_b), 2)
    end
end)

-- 按 C:取消所有标记,停止循环
mp.add_key_binding("c", "repeater-cancel", function()
    mark_a = nil
    mark_b = nil
    looping = false
    mp.osd_message("复读机:已取消所有标记,停止循环", 2)
end)

-- 文件停止/重新加载时自动清理标记
mp.register_event("end-file", function()
    mark_a = nil
    mark_b = nil
    looping = false
end)

使用时,可以把lua脚本放到mpv的设置文件夹里

也可以直接命令行带--script参数

mpv --script=mpv_repeater.lua media1.mp3

现在AI是真的香啊

Reply Favorite View the author
All Replies
avatar
望不穿这暧昧的眼
deepin
3 hours ago
#1

有了AI,全民编程的时代要来了

人人都是产品经理joy

有些人,很懂业务,不懂编程。有了AI辅助,将极大释放其生产力,提高行业效率

Reply View the author
avatar
wils
deepin
3 hours ago
#2
望不穿这暧昧的眼

有了AI,全民编程的时代要来了

人人都是产品经理joy

有些人,很懂业务,不懂编程。有了AI辅助,将极大释放其生产力,提高行业效率

刚搜了下,复读机还有的卖,而且还不便宜joy

效率提高恐怕伴随着断人财路

但总的来说,真香!

Reply View the author