Issue
I have a little application that streams from differents urls from the net, I would like to handle invalid/broken url, I have tried the various catch offered but even when streaming a broken file, I can see my log in the log, all I see is
Error (1,-1004)
here is my code for the moment
mediaPlayer.reset();
try {
mediaPlayer.setDataSource(urlString);
Log.w("myApp", "0");
mediaPlayer.prepareAsync(); // might take long! (for buffering, etc)
playPauseButton.setVisibility(View.INVISIBLE);
progressBar1.setVisibility(View.VISIBLE);
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
// TODO Auto-generated method stub
duration = mediaPlayer.getDuration();
textDuration.setText(getDurationString(duration/1000));
progress.setMax(duration);
playPauseButton.setChecked(true);
mediaPlayer.start();
playPauseButton.setVisibility(View.VISIBLE);
progressBar1.setVisibility(View.INVISIBLE);
}
});
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
Log.w("myApp", "1");
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
Log.w("myApp", "2");
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
Log.w("myApp", "3");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
Log.w("myApp", "4");
e.printStackTrace();
}
Thank you for the help .)
Solution
MediaPlayer.OnErrorListener may help. it's not a exception.so you can't catch it.
onError(MediaPlayer mp, int what, int extra);
official doc. MEDIA_ERROR_IO is extra code.
public static final int MEDIA_ERROR_IO
Added in API level 17
File or network related operation errors.
Constant Value: -1004 (0xfffffc14)
Answered By - venciallee