Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to save audio using mplayer from a live http stream. saving audio is successful. If there is no live stream playing it does not exit automatically. Is there any way to set timeout if there is no live stream?

code : mplayer -i url -t 00:00:10 -acodec libmp3lame -ab 24 -ar 8000 audio.mp3

Thanks in advance.

share|improve this question
add comment

1 Answer

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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