Number of current track and length of m3u playlist


#1

Dear People,

i’ve setup a headless musicbox with RFID and GPIO buttons support for my kids.
Swiping a RFID card starts playback of a local m3u playlist.
The GPIO button offer previous/next track and play/pause toggle functionality.

Anyhow it seems as if my code is too buggy. So when the last track of the playlist is played and I press “next track”, the whole system seems to crash and does not recover. although I can restart playback on the webfrontend.

As I would like to improve the code, the big question is:

  • is there any functionality to get the lenght or number of tracks in die playlist (python) ?
  • is there any functionality to get the tracknumber (within a playlist) of the currently playing track?

#2

I’m going to assume that when you are saying playlist here you are referring to the current playlist (which in Mopidy-speak is known as the tracklist). You could use python-mpd2 to send the MPD status command which will report playlistlength and song as part of the output.

If you wanted to get the length of an arbitrary m3u playlist (i.e. one that has not been loaded into the current playlist) then you can use the listplaylist MPD command and count the number of songs that are returned.


#3

ok, I’m sort of step further now…but I don’t get it.
I’m calling client.currentsong() now and getting this:

id: 7
pos: 0
file: file:///music/MusicBox/dance/01%20-%20Disco%20Pogo.mp3
time: 0

How do I get the mp3-tag information about ‘title’ and ‘artist’ e.g. I’m just getting the filename information.
I also don’t understand the id (here: 7). This is the first song in a loaded playlist (m3u)…where does the 7 come from ?


#4

Regarding the missing metadata, you’re a victim of a known issue that is fixed in https://github.com/mopidy/mopidy/pull/1621 but not merged. I’ve not looked at it since the start of the holiday period but I’ll see if I can move it along now. In the meantime you could pull and use that code, it should be good to go.

The track position in the current playlist is given by pos and starts at 0. The 2nd track would have pos value 1, the 3rd track would have 2, and so on. The id value there is the unique ID for the track in the context of the current playlist. If you were to restart mopidy and then load the m3u that id value should be 0 (or maybe 1, I have some memory that we had to adjust the starting value to match what mpd does).


#5

thank you @kingosticks !
good to know, that i’m not making a mistake…I was about to go crazy :slight_smile:

Honestly I’m not used to github and I’m currently not sure how to get your latest fix…

that brings me to another question: does pi musicbox do a autoupdate as soon the code is updated ?
Or how do I make sure to use the latest version ?


#6

Ahh, yes sorry, I forgot you are using Pi Musicbox here. In which case I am afraid the fix I have linked to probably won’t be compatible with the old version of Mopidy that Pi Musicbox still uses. Which also answers your other question: no, there is no auto update and there is currently no convenient way to ensure you have the latest versions of everything. Some things can be updated if you are careful but it’s not supported by me here. Which means you currently have to reinstall a new image each time you want to update. Usually the settings.ini file can just be copied across but you would have to redo any other customisations you’ve done. I am very aware this is far from ideal and an update mechanism is one of the top improvements planned for Pi Musicbox v1.0 (long overdue and still no release date).


#7

just to understand:
would it be better than to install a plain rasbian and mopidy (not the musicbox dmg) ?
I mean the “only” thing musicbox offers in addition is the (nice) webclient, right ?
but on the other hand it has an old version of mopidy on board, and there is no upgrae mechanismn ?


#8

If you are comfortable using linux (which you seem to be) then yes, better to install plain Raspbian and Mopidy and any extensions you require. The main offering of Pi Musicbox is configuring the entire system from a single settings.ini file. The webclient is just a Mopidy extension and can easily be installed from pip. Even the websettings extension can be used with normal Raspbian.


#9

“comfortable” would be exaggerated, but I’ll fight my way through the thicket :slight_smile:

Thanks for the quick support