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.

itsjeyd
  • 178

2 Answers2

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.

joatd
  • 513
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