Add a random value to a script. Need some help

Discuss your Lua playlist, album art and interface scripts.
Nikk_
New Cone
New Cone
Posts: 3
Joined: 22 Jun 2017 18:14

Add a random value to a script. Need some help

Postby Nikk_ » 22 Jun 2017 18:34

Hello all,

I've been looking for a way to play a files in a playlist in a true random manner - files playing random, from a random starting point and for a random duration.
While there were few other posts on the internet about this same thing, I couldn't find an answer and a way to do this. The closest thing to the above is this addon called Sampler: https://addons.videolan.org/content/sho ... ent=149688
It does a fine job but the problem is that it doesn't play the file for a random duration. It rather plays the files for a predetermined duration.
I googled "random generated number in lua" and tried messing with the lua script to add a line for it but I simply don't know anything about lua and couldn't do anything.

So the Sampler cuts the video onto pieces (samples per item field) and I want each sample to have a random duration (lets say between 10 and 600 seconds, or until it ends) determined by this RNG.
Is this even possible in lua (vlc)? Could anybody help me out and point me a way to do this? Even if it's external program/script or another player. I'm willing to try anything at this point :)

Thank you.

Etoh
Blank Cone
Blank Cone
Posts: 60
Joined: 12 Jan 2013 16:33

Re: Add a random value to a script. Need some help

Postby Etoh » 23 Jun 2017 00:09

For random numbers I think you can use math.randomseed(os.time()) and math.random(range).

Nikk_
New Cone
New Cone
Posts: 3
Joined: 22 Jun 2017 18:14

Re: Add a random value to a script. Need some help

Postby Nikk_ » 23 Jun 2017 09:14

Yeah, that's what I found out from google too, but couldn't make the lua work after inserting it here and there. It just broke. :(
Like I said my understanding of lua is virtually non existent...

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: Add a random value to a script. Need some help

Postby mederi » 23 Jun 2017 14:44

I want each sample to have a random duration (lets say between 10 and 600 seconds, or until it ends)
You can edit "Sampler (PG).lua" script, line 166:

Code: Select all

"stop-time="..(sample_position+sample_duration) "stop-time="..(sample_position+math.random(10, 600))

Nikk_
New Cone
New Cone
Posts: 3
Joined: 22 Jun 2017 18:14

Re: Add a random value to a script. Need some help

Postby Nikk_ » 23 Jun 2017 17:17

Amazing !!! Works like a charm.

Btw, how does the scrip "decide" where the sample will begin? It kind of seems random to me. I tried replacing "start-time="..sample_position with math.random(..) but couldn't determine if that did anything or not. It didn't break the script though, which is a good thing :D
Is there any way to make the above and the number of samples as a random range as well? Just make it fully random :)

Anyway huge thank you for the help and for the script you wrote Mederi.
Top notch work!


Return to “Scripting VLC in lua”

Who is online

Users browsing this forum: No registered users and 23 guests