adding and playing a song in one step

Need help with MPD?
Post Reply
rjoberon
Posts: 2
Joined: August 8th, 2020, 8:27 pm

adding and playing a song in one step

Post by rjoberon »

Hi all,

I am using mpc as client but if I understand the protocol definition¹ correctly, this applies to other clients as well: How can I add and play a song (actually, a web stream) in one step?

Currently, I am doing "mpc insert $URL && mpc next" (which is not one step, but that's ok) but it turns out that this works only when mpd is already playing a song. I wonder why this is the case (as the documentation¹ for the "next" command says "Plays next song in the playlist.") and whether there exists an alternative?

I am not sure how I could use the "play" command in this scenario, since for that I would have to find out at which position the song was added to the queue?!

(What works well is "mpc clear && mpc add $URL && mpc play" but obviously that empties the queue which is not what I want.)

I suppose the scenario is common enough that there's a simple solution which I just oversaw. :-)

Best regards,
Robert


P.S.: A solution for how to get rid of "stale" streams from the queue is also very welcome. With "stale" I mean streams that remain in the queue using the approach described above when switching to another $URL. Is there any way to only remove streams from the queue?



¹ https://musicpd.org/doc/html/protocol.h ... g-playback

max
Forum team
Posts: 1127
Joined: January 15th, 2013, 3:43 pm

Re: adding and playing a song in one step

Post by max »

You can use "addid" which returns the song id of the new queue item, and then use "playid" to play that one.

rjoberon
Posts: 2
Joined: August 8th, 2020, 8:27 pm

Re: adding and playing a song in one step

Post by rjoberon »

Thank you, this looks promising. Apparently "addid" is not supported by mpc but with some lines of Python code and musicpd I could implement what I need.

Post Reply