0

When i am trying to play the .mov files in the android device i am getting an error message "Video Can't Play" if the supported video player hasn't installed in my device. Here i just want to customise the error message to "File format not supported, Please install a media player".

Guys please suggest me how fix this.

Many Thanks

SAHIL
  • 431
  • 6
  • 18
  • 1
    Trap the exception and then throw a new one with the message you want. – Simon Apr 30 '13 at 12:46
  • But i don't want to show the default error message initially, Can you please elaborate it more so that it makes me easy to understand. – SAHIL Apr 30 '13 at 12:53
  • See this..http://developer.android.com/reference/android/widget/VideoView.html#setOnErrorListener%28android.media.MediaPlayer.OnErrorListener%29 – Simon Apr 30 '13 at 12:55
  • check this link and try it [ http://stackoverflow.com/questions/13341560/how-to-create-a-custom-dialog-box-in-android ] – Make it Simple Apr 30 '13 at 13:08

1 Answers1

1

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.
        }

    }
}
Calvin
  • 111
  • 1
  • 1
  • 7