2

I am using mplayer to stream audio coming from an MPD instance that is configured to output via HTTP:

mplayer http://<stream-URL>:<port>

The stream is controlled by an MPD client (Cantata). The stream pauses whenever MPD reaches the end of the play queue defined in the client. When this happens, mplayer exits immediately. I would like for it to keep running and play new content as soon as it becomes available (i.e., as soon as new items are added to the play queue in the client).

I tried running mplayer with the -idle option, and while this does cause mplayer to keep running after the stream stops, no audio output is produced when starting to play content in the MPD client.

How can I make mplayer listen for the stream to become active again and start playing what it is receiving from the stream?

EDIT: MPD is running on a server in my LAN, and Cantata and mplayer are running on my Laptop.

2

It's been a very long time since I played with MPD scripting. Since Cantata has a dBus interface, I shouldn't be too difficult to do what you want. It does, however, lead you into the land of weird dbus controls.

Part of the answer is that -idle doesn't cause mplayer to attempt reconnecting to your streaming source. It only prevents mplayer from exiting.

This isn't to say that what you're seeking can't be done. It's likely you'll need a bit of external scripting to trigger mplayer to reconnect. In any case, to enable remote control of mplayer, run the following:

mkfifo /home/you/.mplayer/cmd.fifo
mplayer -idle -input file=/home/you/.mplayer/cmd.fifo

After that, any time you run something similar to the following, you can cause mplayer to reconnect.

echo "loadfile http://yourserver.com:8000/yourstream.mp3" >> /home/you/.mplayer/cmd.fifo

This is about as far as I can take it without playing with Cantata's dbus interface. A bit of research should turn up what's needed.

Note: running the loadfile command while a stream is being played causes a noticeable break in the audio.

It may also be valuable to note here: is MPD, mplayer, and Cantata all on the same box or on separate systems?

Hope this helps.

  • Thanks for the answer. Re: your question about whether or not the three programs are running on the same box: They are not. I added some more information about what is running where to my question. – itsjeyd Jan 2 '14 at 21:21
  • Your suggestions about enabling remote control for mplayer work for me, I just tried them out, so thanks again. The thing is though, if I have to go back to my terminal every time I start playing music again in Cantata I might as well restart mplayer. I'd really like to find a solution that would enable me to start mplayer once and have it do the right thing without having to interfere with it. Unfortunately my experience with D-Bus is very limited, so if there's really no way to call mplayer in a way that will make it do what I want I'd appreciate any additional pointers w/r/t D-Bus. – itsjeyd Jan 2 '14 at 22:14
  • Have you looked at Liquidsoap? It's a scripting language for writing audio controls and services. I use it in place of mpd to run what amounts to an in-house jukebox. When there's no selections made, it plays a random song. In the meantime, if you don't want to monitor Cantata via dbus, I think your only other option is polling mpd every few seconds for status (like mpd.wikia.com/wiki/Hack:stream-monitor). The short-comings for this are: eats up a noticeable amount of processing power and the first second or two of a song may be missed (caused by the time between polls). – joat Jan 4 '14 at 9:24
2

I do not have anything heared about cantata, but when i use my mobile internet radio while driving in the car i ran in the same problem to restart mplayer if connection is broken. simply i put the mplayer command in an endlesloop controlled by a variable that is set false for easy switching off, adding 3 seconds pause after abort not to overload something.

runplayer=true
while $runplayer
do mplayer "http://yourserver.com:8000/yourstream.mp3" 
sleep 3
done   
  • I've been simply doing "while true; do mplayer ... ; done" - the variable idea is great. – andrew lorien Apr 4 at 4:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.