Custom Frontend Track Change Sequence

I’m working on developing a new frontend that allows multiple users to access the web interface and queue up whatever music they want, then there is a voting feature that randomly picks two songs from the queue and places them head-to-head and allows users to vote on which one they want to hear next. At the end of the playback of the current track, the winner gets queued up as the next to play and two more tracks are chosen at random for the next head-to-head.

The issue I’m running into is this: I need to intercept when a track has finished playing in order to be able to set up the winner of the vote as the next track to play. I have access to all of the frontend api functionality, and have tried using the ‘track_playback_ended’ event to trigger this action, however it appears that this event gets triggered either after or in parallel with the next track in the tracklist beginning its playback. This causes an issue because I have the tracklist set to ‘consume’ tracks as they are played, so even this sliver of a time that the next track in the list is being played is enough for it to then be removed from the tracklist once the voting winner begins its playback. This causes the first song in the tracklist being removed without it ever being played.

Looking at the mopidy code, there are a few methods that look promising, mainly ‘_on_about_to_finish’ and _on_about_to_finish_callback’, which appear to be executed prior to the end of song playing. Is there a way to tap into the timing I’m looking for using these methods/events without having to code a backend component as well? Is there another way to accomplish what I’m looking to do?


Have you considered re-evaluating the tracklist order every time a vote is cast rather than waiting to do that just before track change? Those internal events/callbacks you list are for supporting gapless playback and they are not designed with other usage in mind.

That’s a good alternative, thanks–I may come back to that if I’m not able to get it working otherwise. I think I may also be able to handle my own dropping of tracks rather than relying on the ‘consume’ mode to drop the currently playing track, which may give me what I need.