Playlists and Item IDs

Discuss your Lua playlist, album art and interface scripts.
bergur
New Cone
New Cone
Posts: 3
Joined: 30 Jul 2013 16:23

Playlists and Item IDs

Postby bergur » 30 Jul 2013 17:44

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.

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: Playlists and Item IDs

Postby mederi » 30 Jul 2013 19:38


bergur
New Cone
New Cone
Posts: 3
Joined: 30 Jul 2013 16:23

Re: Playlists and Item IDs

Postby bergur » 30 Jul 2013 21:29

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?

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: Playlists and Item IDs

Postby mederi » 31 Jul 2013 13:15

I really do not know the cause of this discrepancy. Possible bug?

Rita VLC
Blank Cone
Blank Cone
Posts: 12
Joined: 03 Dec 2013 01:52

Re: Playlists and Item IDs

Postby Rita VLC » 03 Dec 2013 13:22

It could be a bug.IDs should match and it's not happening in this case

bcourts
New Cone
New Cone
Posts: 9
Joined: 26 Feb 2014 03:28

Re: Playlists and Item IDs

Postby bcourts » 26 Feb 2014 05:03

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


Return to “Scripting VLC in lua”

Who is online

Users browsing this forum: No registered users and 1 guest