I have a MediaPlayer that plays with the following code:
private void playVideo() {
if (videoURI == null) {
showToast("Please, set the video URI in HelloAndroidActivity.java in onClick(View v) method");
} else {
new Thread(new Runnable() {
public void run() {
try {
player.setOnErrorListener(new OnErrorListener()
{
@Override
public boolean onError(MediaPlayer mp,
int what, int extra) {
Log.e("MEDIAPLAYER ERRORS",
"what: " + what + " extra: " + extra);
return false;
}
});
Log.d("video","---+ in main run");
player.setDataSource(videoURI);
player.prepare();
player.reset();
} catch (IllegalArgumentException e) {
Log.d("video","---+ illegal arg");
showToast("Error while playing video");
Log.i(TAG, "========== IllegalArgumentException ===========");
e.printStackTrace();
} catch (IllegalStateException e) {
Log.d("video","---+ illegal state");
showToast("Error while playing video");
Log.i(TAG, "========== IllegalStateException ===========");
e.printStackTrace();
} catch (IOException e) {
Log.d("video","---+ general error");
showToast("Error while playing video. Please, check your network connection.");
Log.i(TAG, "========== IOException ===========");
e.printStackTrace();
}
}
}).start();
}
}
On error, my app goes into an infinite error loop with the following messages:
03-05 13:27:23.035: E/MediaPlayer(6289): stop called in state 0
03-05 13:27:23.035: E/MediaPlayer(6289): error (-38, 0)
03-05 13:27:23.035: E/MediaPlayer(6289): Error (-38,0)
03-05 13:27:23.043: E/MEDIAPLAYER ERRORS(6289): what: -38 extra: 0
What is the best way to recover from the error that is caught? Should I abort the mediaplayer and if so how do I accomplish this? Also how can I stop from going into this error loop in the first place?
Thanks!
Is there something missing from your code? It doesn’t seem to me like it would ever actually start the MediaPlayer anywhere in what you’ve posted.
It also seems odd to me that you call
after the others. I would think this would undo the setDataSource(), and prepare() that you just got finished with. Try moving reset so that it is the first one called.
and try putting this in your onErrorListener callback:
That way it will just try to remake the whole thing when it gets this error.