Switching between playlist


it’s been a while since I worked with Mopidy. 4 years ago I was working on a retro radio which was equipped with an Raspberry Pi. I wrote an extension to control the external amplifier (https://github.com/avanc/mopidy-tpa2016d2). These days I would go for a HifiBerry for sure :slight_smile:
I also developed a input device driver for the rotary encoders (https://github.com/avanc/rotary-encoder) in addition to a frontend (https://github.com/avanc/mopidy-headless) to control volume an switch playlists.

I was able to get a working prototype. Unfortunately, it was not really used due to other reasons…
However, now it is time to give it a new try. To make sure, I develop into the right directions I want to discuss my requirements:

  1. I want to have several playlists: radio stations as well as local music
  2. Switch between playlist (next, previous)
  3. Configure some playlists as random play
  4. Optional: Continue playlists

The first requirement is already fulfilled with the m3u extension.
Is there already a command to switch playlists (2.) or do I have to write a backend extension which clears current play queue?
Is it possible to play the content of some playlists randomly by default (3.)?
Is it possible to store state of played playlists and resume at the same track or even better at the exact position in one track (4.)?

Any hints or points to some APIs would help.


Most of this can be found in our documentation.

  1. The current playlist is manipulated through the core API. Backends do not manipulate the core API. It would be a frontend extension. However you can probably do what you want just using mpc to talk to the existing MPD frontend.

  2. As above.

  3. You can easily dump the status using mpc but would need to come up with something that would store/restore it per-playlist and trigger it appropriately. You could also do it with a frontend extension, doing that might make it simple to listen for events that you can then use to trigger the store/restore you need.

So either a simple frontend or maybe even a bash script (calling mpc) would suffice.

Thanks, never played with mpc before. Sounds like a good solution. However, I already fail with the basics:

mpc ls

lists “Files”, “Local media” and my created playlists. But

mpc add MyPlaylist

fails with “error adding MyPlaylist: directory or file not found”. What I’m doing wrong?

add <file>

Adds a song from the music database to the playlist. Can also read input from pipes. Use “mpc ls | mpc add” to add all files to the playlist.

You cannot add a (stored) playlist file. You must list a (stored) playlist file’s songs and add them as per the above example. Or, you can load a (stored) playlist file:

load <file>

Loads <file> as playlist.

Thanks, I got confused by my playlists and the current playlist (aka queue).

My old HW setup is running again. Now I have to dig into the details :slight_smile:
Is there any clean solution to play a playlist on startup of mopidy, or do I have to do mpc load <playlist name>; mpc play after some time delay to be sure mopidy is fully started?

You are correct. You need something external to wait some amount of time (or poll something).

I decided to use my old frontend to switch between playlists instead of using mpc. However, I’m doing something wrong while adding a playlist to the track list:

#Get all playlists
self.playlists = []
for playlist in self.core.playlists.playlists.get():


However, the tracklist ist still empty. I guess it is a similar misunderstanding as with mpc discussed above, but I cannot find something similar to mpc load in the API doc.

You’d probably want to do self.core.tracklist.add(uri=self.playlists[0].uri).get() to make sure the tracks are actually added before you call play(). However, I don’t think (I can’t 100% remember) that all backends support expanding playlists into tracks like tracklist.add requires. You might as well just expand the playlist yourself. You can see how the MPD frontend does this: https://github.com/mopidy/mopidy/blob/develop/mopidy/mpd/protocol/stored_playlists.py#L147-L148

It works with your proposal. Thanks for your quick help.