Alexis
Alexis

Reputation: 25163

Android's MediaPlayer prepareAsync() timeout?

I am using MediaPlayer's prepareAsync() function.

My code looks like:

try {
  mediaPlayer.setDataSource(stream_url);
  mediaPlayer.prepareAsync();
} catch (Exception e) {
  e.printStackTrace();
}

mediaPlayer.setOnPreparedListener(new OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer mp) {
        mp.start();
    }
});     

The issue is that sometimes stream_url is playing music, and sometimes stream_url is not playing music. How can I notify the user if stream_url is not playing music? Is there a timeout of some sort or an error I can catch? Nothing is currently being thrown, it just calls asycn then does nothing if there is no stream.

Upvotes: 3

Views: 4114

Answers (1)

Simone Casagranda
Simone Casagranda

Reputation: 1215

If you take a look to documentation there are son available setter for listener and there is a setter that allows you to check error on async operation.

MediaPlayer.OnErrorListener 

Interface definition of a callback to be invoked when there has been an error during an asynchronous operation (other errors will throw exceptions at method call time).

Upvotes: 2

Related Questions