Here is another attempt:
Code: Select all
-- "New Random with Loop all.lua" -- VLC Extension
first_ID = 6
items = 10
random_order={3,5,8,2,9,4,7,1,10,6}
function descriptor()
return {
title = "New Random with Loop all",
capabilities = {"input-listener", "meta-listener"}
}
end
function activate()
create_dialog()
end
function deactivate()
end
function close()
vlc.deactivate()
end
k=0
function input_changed()
state = vlc.var.get(vlc.object.input(), "state")
--vlc.msg.info("["..descriptor().title.."] Input state = "..state)
if state==4 then
k=k+1
if k>#random_order then
k=1
New_Random()
end
vlc.playlist.goto(random_order[k]+first_ID-2)
--vlc.msg.info("["..descriptor().title.."] ".. k ": goto(" .. random_order[k] .. "+"..first_ID.."-2)")
order=""
for ix, vx in ipairs(random_order) do
if ix==k then vx="<b>["..vx.."]</b>" end
order=order..vx..", "
end
w8:set_text(order)
w:update()
end
end
function meta_changed()
end
----- Dialog box: -----
function create_dialog()
w = vlc.dialog(descriptor().title)
w1 = w:add_label("ID of the first item:", 1, 1)
w2 = w:add_text_input(first_ID, 2, 1)
w3 = w:add_button("Check ID:",click_CheckID, 3, 1)
w4 = w:add_label("Number of items:", 1, 2)
w5 = w:add_text_input(items, 2, 2)
w6 = w:add_label("Random order", 1, 3, 2)
w7 = w:add_button("START",click_Start, 3, 3)
w8 = w:add_html("", 1, 4, 3)
end
function click_CheckID()
w3:set_text("Check ID: " .. vlc.playlist.current())
end
function click_Start()
k=0 -- playback reset
New_Random()
order = ""
for _, v in ipairs(random_order) do
order = order..v..", "
end
w8:set_text(order)
end
----- Generator of random order: -----
i=0
function New_Random()
i=i+1
first_ID = w2:get_text()
items = w5:get_text()
random_order = {}
for j=1,items do
random_order[j] = j
end
-- Initialize the pseudo random number generator
math.randomseed( os.time() )
math.random(); math.random(); math.random()
-- done. :-)
random_order = shuffle(random_order)
w6:set_text("Random order #"..i)
end
function shuffle(t)
local n = #t
while n > 2 do
-- n is now the last pertinent index
local m = math.random(n) -- 1 <= m <= n
-- Quick swap
t[n], t[m] = t[m], t[n]
n = n - 1
end
return t
end
INSTRUCTIONS:
* feed VLC playlist with files;
* VLC Random is off, Loop is off, start to play the first file;
* activate the extension in VLC menu;
* press [Check ID:] button;
* write the ID in the text input field (usually value 5 or 6);
* how many files are there in the playlist (you can activate ID column in VLC playlist (right-click on the header) in Detailed View);
* press [START] button;
* stop the playback of the first file in the playlist;
=> playback continues in random order
A new random order will be automatically generated at the end of the last file in current random order or you can press [START] button again anytime.
Starting VLC with
--play-and-stop CLI parameter could help (desktop shortcut icon or batch file). Appropriate setting in VLC preferences: Tools > Preferences > ( Show settings = All ) > Playlist:
[v] Play and stop >> Save changes, restart VLC.