这似乎应该很简单,但我在这里空手而归。我正在尝试制作一个简单的VLC脚本,检查“随机”按钮是否打开,如果它跳转到随机文件,而不是在时间= 0开始,它将随机开始。
到目前为止,它正在寻找我喜欢它应该是一个播放列表脚本,我可以从播放列表对象获得持续时间,但在this documentation page或Google,我似乎没有找到任何方式跳到一个特定的时间内Lua脚本。有没有人有更多的经验来控制VLC播放与Lua?
解决方法
实际上,文件确实说你可以做到这一点,尽管不是这么多话。以下是播放列表解析器的界面说明:
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)
如果你遵循playlist.add()的描述,它说这些项目有一个很大的可以提供的字段列表。有很多选择(.name,.title,.artist等),但唯一需要的一个似乎是.path …这是“项目的完整路径/ URL”。
没有明确提到在哪里寻找,但您可以选择提供的参数之一是.options,被称为“VLC选项列表”,以全屏为例,如果平行到全屏幕工作,可以其他命令行选项如 – 启动时间和停止时间工作?
在我的系统上,他们做,这里是脚本!
-- 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