Search code examples
javaandroidvideomedia-player

Play Video Using External Media Player in Android


Well, I've used VideoView to play my Video. It only support .mp4 format(Correct me if I'm wrong), I need to play .flv video. I've MX Player/VLC player installed on my Android phone. How do I load the list of available Media Players when I click Play Video Button in my Activity.

Below is the code I've written using Video View, if it helps

public void onClick(View v) {
            File root = Environment.getExternalStorageDirectory();                
            String externalFilesDir = getExternalFilesDir(null).toString();       
            String videoResource = externalFilesDir +"/" + "VID_20160115_215637181.mp4";
            mediaController.setAnchorView(videoView);
            videoView.setMediaController(mediaController);
            videoView.setVideoPath(videoResource);
            videoView.requestFocus();
            videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mp) {
                    videoView.seekTo(0);
                    videoView.start();
                }
            });
        }

Solution

  • If You want to play video in some other player, you can use ACTION_VIEW intent

    Example in this question: Android intent for playing video?