Need suggestions/ideas for initiating Mopidy from the web

I’m running Mopidy on a raspberry Pi and I’m making a kiosk-type display that will host a web page in full screen mode. It’s a touchscreen device, so users can couch menu items to interact with it.

I’m able to run Mopidy on my Pi just fine and I’m able to incorporate the HTTP web clients to display my music library, but I’m trying to think of a way to allow the user to initiate mopidy from within the interface. The reason for this is simple: Spotify doesn’t let multiple sessions run simultaneously. So, if I use Spotify elsewhere in my life while Mopidy is running, it will require a restart of mopidy in order to run correctly.

Ideally, I’d like to send a request form my local HTML page that can start Mopdiy so the session will always be fresh and force-close any other Spotify session running out there. Any suggestions?

Have you tried switching between the two?
If I’m using spotify on my laptop then switch to mopidy on the Raspberry Pi, it stops playing on the laptop and puts a message saying ‘Spotify is paused as my account is being used elsewhere’ then starts playing mopidy on the Pi and vice versa.
There is about a half second overlap whilst one stops and the other kicks in but I don’t need to reboot or restart anything.

1 Like

So it does… Weird. I got an error last time.

I switch between RPi, laptop and mobile quite often when listening to Spotify and I’ve never experienced the mopidy instance being permanently kicked out. If you’ve got similar issues it probably means either that the other client was keeping streaming (or attempting to), thus preventing the mopidy client from accessing the stream, or Spotify cached the status incorrectly on their side, but nothing that is supposed to be permanent.

If you still need to programmatically restart the mopidy instance for any other reason, have you considered wrapping mopidy into a systemd service (which should be pretty much supported on all the Linux distros) and just run systemctl restart from your code? It sounds easier and neater than wrapping the mopidy instance into its own controller to allow programmatic restarts.