这似乎应该很简单,但我在这里空手而归.我正在尝试创建一个简单的VLC脚本来检查"随机"按钮是否打开,如果是,当它跳转到随机文件时,而不是从时间= 0开始,它会在随机时间开始.
到目前为止,它看起来像我应该是一个播放列表脚本,我可以从播放列表对象获取持续时间,但在这个文档页面或谷歌,我似乎无法找到任何方式跳转到特定时间在Lua脚本中.有没有人有更多使用Lua控制VLC播放的经验?
Hos*_*ork 21
实际上,文档确实说你可以做到......虽然不是那么多的话.以下是有关播放列表解析器界面的说明:
VLC Lua playlist modules should define two functions:
* probe(): returns true if we want to handle the playlist in this script
* parse(): read the incoming data and return playlist item(s)
Playlist items use the same format as that expected in the
playlist.add() function (see general lua/README.txt)
Run Code Online (Sandbox Code Playgroud)
如果您按照说明进行操作,playlist.add()则说明这些项目包含您可以提供的大量字段.有很多的选择(.name,.title,.artist等),但唯一需要的人似乎是.path......这是"该项目的完整路径/ URL".
没有明确提到在哪里寻找,但你可以选择提供的参数之一.options,据说是"VLC选项列表.它给出fullscreen了一个例子.如果并行--fullscreen工作,可以像其他命令行选项一样--start-time还有--stop-time工作吗?
在我的系统上,他们这样做,这是脚本!
-- randomseek.lua
--
-- A compiled version of this file (.luac) should be put into the proper VLC
-- playlist parsers directory for your system type. See:
--
-- http://wiki.videolan.org/Documentation:Play_HowTo/Building_Lua_Playlist_Scripts
--
-- The file format is extremely simple and is merely alternating lines of
-- filenames and durations, such as if you had a file "example.randomseek"
-- it might contain:
--
-- foo.mp4
-- 3:04
-- bar.mov
-- 10:20
--
-- It simply will seek to a random location in the file and play a random
-- amount of the remaining time in the clip.
function probe()
-- seed the random number since other VLC lua plugins don't seem to
math.randomseed(os.time())
-- tell VLC we will handle anything ending in ".randomseek"
return string.match(vlc.path, ".randomseek$")
end
function parse()
-- VLC expects us to return a list of items, each item itself a list
-- of properties
playlist = {}
-- I'll assume a well formed input file but obviously you should do
-- error checking if writing something real
while true do
playlist_item = {}
line = vlc.readline()
if line == nil then
break --error handling goes here
end
playlist_item.path = line
line = vlc.readline()
if line == nil then
break --error handling goes here
end
for _min, _sec in string.gmatch( line, "(%d*):(%d*)" )
do
duration = 60 * _min + _sec
end
-- math.random with integer argument returns an integer between
-- one and the number passed in inclusive, VLC uses zero based times
start_time = math.random(duration) - 1
stop_time = math.random(start_time, duration - 1)
-- give the viewer a hint of how long the clip will take
playlist_item.duration = stop_time - start_time
-- a playlist item has another list inside of it of options
playlist_item.options = {}
table.insert(playlist_item.options, "start-time="..tostring(start_time))
table.insert(playlist_item.options, "stop-time="..tostring(stop_time))
table.insert(playlist_item.options, "fullscreen")
-- add the item to the playlist
table.insert( playlist, playlist_item )
end
return playlist
end
Run Code Online (Sandbox Code Playgroud)