MPD
MPD copied to clipboard
Question: prevent mpd/mpc to jump to the next stream?
I use mpd/mpc on my kitchen web radio. It is a Raspberry Pi Zero with a Hifiberry Mini Amp and my own Web Interface to control mpd/mpc.
It works great for years! Thank you developing and maintenance this software!
Now I got a problem with my favorite station absolut musicXL (stream).
If musicXL play Advertisement, mpd/mpc jump to the next stream in my playlist. It seems that mpd/mpc detect an end of the stream when they play Advertisement and than jump to the next stream.
Now my question: Is it possible to prevent mpd/mpc to jump to the next stream?
They basically have misconfigured streaming service. When advertisement turns on - they really interrupt the stream, rather than just changing the track and MPD detects that as end of "track" (because server closes connection briefly).
Same would happen if you e.g. set up a MPD instance with httpd output and will try to connect to stream from another MPD instance, then stopping stream, inserting some other tracks and starting playback. MPD streaming by default (unless "always_on" option is not set on httpd output) will close the stream and listeners would be disconnected.
While it's not entirely impossible to work around this problem on player side (and some players that support playing web streams actually do, probably, by trying to reconnect to stream after losing stream, either continuously or up to some timeout), the root cause is on stream side, because properly configured web radio should produce continuous stream and advertisements should not interrupt the stream.
That said, MPD reads web radio through libcurl and it might be possible to configure it to resume stream connection if it's closed, though MPD doesn't seem support this currently.
However, this problem can be worked around completely outside the MPD itself. As long as you want to prevent MPD to switching to the next stream, you can just use following bash command:
while :; do mpc idle player; mpc prev || break; done
While this command runs, it effectively prevents MPD from going to next track. It's just a loop that repeatedly does:
mpc idle player
- This waits for any player state events (that is, start of playback, track switch, stop or pause).
mpc prev
- This would switch to the previous track.
So whenever advertisement starts (or stops) and player switches to next track, it would just jump back to previous track. To stop this behavior - just Ctrl+C would work.
Note that this is not a perfect solution, though (since e.g. pause is also a player event, using pause while this command runs would jump to previous track/stream) and if you expect to use pause while listening to streams - then a more sophisticated bash function would be needed that will properly check which track is playing now after receiving player event.
Thank you for your answer and your suggested solution! I do not try your solution until now but I think it could bee, that thats starts an Advertisement Loop.
However I tested an other stream from Absolutradio (stream MusicXL) and that seems to work a bit better.
There mpd/mpc do not jump to the next stream but sometimes it plays with a wrong speed. Crazy!