I've solved it by using Expect. You launch the streaming playing with ./play.sh
:
while [ '1' == '1' ];
do
expect try_stream.exp $1
sleep 3
done
And this uses try_stream.exp
:
set timeout 4
spawn mplayer -nocache $argv
expect {
"Starting playback" {
interact
}
timeout {
send \003;
exit 1
}
}
Basically, it tries to play the stream, and if it cannot do it within 3 seconds, it gives up (.exp script) and retries (.sh script). It works as long as you have problems like a very busy server. Unfortunately I don't know how to deal with the case when mplayer gets stuck once it started playing, there is no output string for Expect to detect in such a case.