Add to Favourites / Playlist in Player Dashboard

Hi there,

When developing a plugin that uses MPD for playing audio, it is convenient to call setConsumeUpdateService('mpd') so that you don’t have to handle the player states yourself. However, adding a currently playing song to Favourites or a Playlist from the player dashboard (the view where you have two circles on each side and album art in the middle) will most likely fail because:

  • The ‘service’ that is passed to the PlaylistManager would become ‘mpd’ and not your plugin; and
  • The uri may not be handled correctly by the PlaylistManager’s inbuilt commonAddToPlaylist() function.

I have looked at Volumio’s code and was kinda dumbfounded:

  1. When browsing items in sources and adding an item to Favourites / Playlist, the following happens:

    • PlaylistManager receives the service and uri for that item, e.g. for the YouTube2 plugin, the service would be ‘youtube2’ and uri would be something like ‘youtube2/video@videoId=…’.

    • Now, since the service is not one that is recognised by PlaylistManager, the uri is ‘exploded’ and the title, album, artist, etc. of the first item is used for the Favorite / Playlist entry (doesn’t make sense, but I’ll live with it for the time being…)

  2. Now, when you add a song to Favourites / Playlist in the player dashboard, the following happens:

    • PlaylistManager receives the service and uri for the song. The uri would be the actual audio URI (as opposed to the URI pointing to the source item that triggered the playback) and, if setConsumeUpdateService('mpd') was called in your plugin, the service would be ‘mpd’.

    • If setConsumeUpdateService('mpd') was called, then PlaylistManager would process the audio URI as though it were provided by the MPD plugin…and fail.

    • If setConsumeUpdateService(‘mpd’) was not called, then your plugin will have a chance to handle ‘Add to Favourites’ requests…but not for Playlists. This is because in addToFavourites(), the PlaylistManager checks to see if your plugin defines a function of the same name and calls it if it does. This kind of check is non-existent in addToPlaylist().

I would imagine Volumio would be able to associate the song shown in the player dashboard with the source item that triggered its playback (through the StateMachine or whatever). If so, it could then pass the service and uri for the source item to PlaylistManager instead of going through the mess in (2) (and also be consistent with (1))?

Please correct me if I have missed anything of importance.


1 Like