How to check if a file is supported with android videoview code?

I am trying to play a video using Android video capture. Here is my code:

super.onCreate(savedInstanceState);
setContentView(R.layout.video);
VideoView videoView = (VideoView) findViewById(R.id.videoView);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();

This works great, but some phones still display a dialog box that says "Unable to play video."

My question is: how to disable this notification window? I mean, can I check if the video file is supported or not, before calling videoView.start ()? Or can I disable or prevent the system from popping up a window?

I would just like to skip the video if it is not supported by the phone, without a notification window.

+5
source share
2 answers

setOnErrorListener , VideoView, , .

    // Restart if PROBLEM
    myVideoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {

        public boolean onError(MediaPlayer mp, int what, int extra) {
            // TODO Auto-generated method stub
            Intent intent = getIntent();
            overridePendingTransition(0, 0);
            intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);

            finish();

            overridePendingTransition(0, 0);
            startActivity(intent);

            return true;
        }

    });
    myVideoView.start();
+3

MediaPlayer .

try {
    MediaPlayer mp = MediaPlayer.create(this, uri);
    mp.release();
} catch (Exception e) {
    Log.e("MediaPlayer", "can NOT play: " + uri);
}

, VideoView, , , mkv/mpg .

, . , - .

0

All Articles