after vlc.volume.set(), vlc.volume.get() returns the previous value!

Discuss your Lua playlist, album art and interface scripts.
hedgehog90
Blank Cone
Blank Cone
Posts: 12
Joined: 16 Nov 2018 13:04

after vlc.volume.set(), vlc.volume.get() returns the previous value!

Postby hedgehog90 » 05 Mar 2020 16:17

If I run the following LUA script in VLC I'd expect to print 1 to 10:

Code: Select all

for i = 1,10 do vlc.volume.set(vlc.volume.get()+1) print(vlc.volume.get()) print(" ") end

However, this is my result: 1 1 2 2 3 3 4 4 5 5

On another occasion, I get a different result: 1 1 1 2 2 3 3 4 4 5

If I wait for a small amount of time between setting and getting however, I consistently get the expected result:

Code: Select all

for i = 1,10 do vlc.volume.set(vlc.volume.get()+1) vlc.misc.mwait(vlc.misc.mdate() + 2000) print(vlc.volume.get()) print(" ") end

Result: 1 2 3 4 5 6 7 8 9 10

If I wait for any less than 'vlc.misc.mdate() + 2000' then I occasionally print the same value twice.

I am running this code via the HTTP interface using VLC 3.0.8. I haven't tested but I assume this can be replicated with any vlc based get/set.

I assume this is a quirk of the system rather than a bug.
What is the correct way to check for updated values in a LUA script like the one above?

Rémi Denis-Courmont
Developer
Developer
Posts: 15278
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: after vlc.volume.set(), vlc.volume.get() returns the previous value!

Postby Rémi Denis-Courmont » 06 Mar 2020 17:40

For historical reason, it's called "set", but it's really just sending a request to the audio output to change the volume as soon as possible.

To see the current volume, you need to track the volume variable. This is not possible in Lua, only native.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded


Return to “Scripting VLC in lua”

Who is online

Users browsing this forum: No registered users and 18 guests