Probably a stupid question, but how do I do this? I assumed there would be some kind of simple socket.emit command for this, but I can’t seem to find it.
Or do I have to draw in the tracks from the album and add each one individually to the queue?
Any help appreciated!
Just use the album uri in play command like any track or playlist.
Hey thanks Joni
I wonder if you could just help me with a few details.
in the API docs, the play command is mentioned but it doesn’t have any variables you can send to it. I’m light of that what exact format would I send using the socket.emit command?
I was wondering if it was replaceAndPlay which is mentioned in the REST API but strangely not in the websocket one.
Sorry if this is a dumb question but I’ve just never actually seen this command explained anywhere
Also with the album do I need to preface it with album:// and do I need to set the service as mpd?
Thanks!
Hello loisandthecat,
Did you figure it out ? If yes, then how. I am struggling with recieving an album uri in the first place using the api for playing it. It does not get pushed by any api commands I tried…
In case you have not found a solution, here is something that should work if supplied with an album uri
Here is a code snippet from my python project:
It uses the socketIO-client module
#python3
from socketIO_client import SocketIO
class Volumio:
def __init__(self, address="localhost", port=3000):
"""
Class for interacting with the Volumio socket.io server.
:param address: Server address (default is "localhost").
:param port: Server port (default is 3000).
"""
# Create a socket and connect to the Volumio server
self._sock = SocketIO(address, port)
self._waiting = 0.1
def _send(self, command, args=None, callback=None):
"""
Send a command to the socket.io server.
:param command: Command to send.
:param args: Arguments as a dictionary.
:param callback: Callback function called upon receiving the response.
:return: None
"""
# Emit the command to the server and wait for callbacks
self._sock.emit(command, args, callback)
self._sock.wait_for_callbacks(seconds=self._waiting)
def play_uri(self, uri, service):
"""
Immediately plays the specified URI.
:param uri: URI
:param service: Service used to play the uri
:return: None
"""
# Brute force method: clear the queue and add a song, or it will be added to the end of the queue
self._send("clearQueue")
self._send("addPlay", {"status": "play", "service": service, "uri": uri})
volumio = Volumio()
uri = "spotify:album:youruri" #spotify uri as an example
service = "spop" #spop in case of spotify,
volumio.play_uri(uri, service)
Hey thanks for the code!
This worked for me:
socket.emit(‘replaceAndPlay’, {“name”: “Mixmaster”, “service”: “mpd”, “uri”: “artists://xxx”});
And to get the album, I play it and then it comes up in the console logs which you can access with the journalctl command (-f if you want to see it live)
You have to look for it but there should be a line in there which explains the url
I think the construction of the url is basically the album folder but I may be wrong.
Hope that helps!