Have you tried OnErrorListener? It allows you to catch errors from the MediaPlayer and react accordingly. If you return true from the OnErrorListener.OnError Method then it indicates that you have handled the error and it should not show that error.
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnErrorListener;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MediaActivity extends Activity implements OnErrorListener{
MediaPlayer mpPlayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_media);
//Code to setup MediaPlayer
mpPlayer.setOnErrorListener(this);
}
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
try{
//Handle error however you like i.e with custom message and dialog
return true; //This indicates that your code handled the error and the OS will not handle the error further.
}catch(Exception exception){
return false;// reutrning false indicates that your code did not handle the error and the OS will display whatever the default error message is.
}
}
}