Page 1 of 1

Playlists and Item IDs

Posted: 30 Jul 2013 17:44
by bergur
Can anyone explain to me how the IDs in playlist work? What I'm trying to do is to check if the current song/video is the first song in the playlist. I can't seem to find a smart way to solve this.

I've got a playlist/table with 15 entries. It looks like this.

Code: Select all

children = { { duration = 82.860437, flags = {}, id = 4, item = <userdata 1>, name = "This Lullaby", nb_played = 1, path = "file:///C:/Music/Lullabies%20To%20Paralyze/01%20-%20This%20Lullaby.mp3" }, { duration = 114.4425, flags = {}, id = 5, item = <userdata 2>, name = "Medication", nb_played = 1, path = "file:///C:/Music/Lullabies%20To%20Paralyze/02%20-%20Medication.mp3" }, .....
When I use playlist.current() to get current input item id, the numbers don't match.

When I play the first song this is the output. As you can see the first-item-id matches the one in the table, but not what current() is returning.

Code: Select all

lua debug: [mytest] first-item-id = 4 lua debug: [mytest] current-item-id = 5
When I play the second song this is the output.

Code: Select all

lua debug: [mytest] first-item-id id = 4 lua debug: [mytest] current-item-id = 6
When according to the table current-item-id for the 2nd song should be 5. Also when I'm in the playlist GUI and choose to see the ID field (Title, Duration, Album, etc). It shows ID 1 to 15.

Can anyone explain this mismatch to me and/or how to check if the item playing is the first item in the playlist.

Re: Playlists and Item IDs

Posted: 30 Jul 2013 19:38
by mederi

Re: Playlists and Item IDs

Posted: 30 Jul 2013 21:29
by bergur
Yeah that works, but I'm just curious why currentID wouldn't match the ID from the playlist table? These IDs should be the same, right? Why is it -1?

Re: Playlists and Item IDs

Posted: 31 Jul 2013 13:15
by mederi
I really do not know the cause of this discrepancy. Possible bug?

Re: Playlists and Item IDs

Posted: 03 Dec 2013 13:22
by Rita VLC
It could be a bug.IDs should match and it's not happening in this case

Re: Playlists and Item IDs

Posted: 26 Feb 2014 05:03
by bcourts
In older versions of VLC (2.0.8 and others) vlc.playlist.current() returns the item's ID in the playlist + 1. In newer versions of VLC (2.1.2 and possibly more), current() returns the item's ID in the playlist. If you want a Lua script using current() to work in both older and newer versions, you need to determine an ID_OFFSET of either 0 or 1. I tried various methods to determine the offset, checking playlist ID's versus the one returned by current() but wasn't able to make any of them work consistently. Using the fact that vlc.misc became inaccessible from Lua extensions at or about the same version where the offset changed, the following works for me on versions 2.0.8 and 2.1.2:

In your extension's activate() function, BEFORE any calls to functions that need a current ID, include the following:

Code: Select all

if vlc.misc then -- this is an older VLC version, and needs the offset ID_OFFSET = 1 else -- this is a newer VLC version, and needs no offset ID_OFFSET = 0 end
And wherever you need the current item's ID, use

Code: Select all

current_id = vlc.playlist.current() - ID_OFFSET