1

I'm using this piece of code to try and open a .mp4 video:

VideoView videoView=(VideoView)findViewById(R.id.videoView1);
MediaController mediaController=new MediaController(this);
mediaController.setAnchorView(videoView) ;
videoView.setVideoPath("R.raw.videoname");
videoView.setMediaController(mediaController) ;
videoView.start(); 

However, whenever I try to run the app, I get a message saying "Can't play this video". I am using a new Nexus 7 tablet if that means anything.

Also, when I try to open the same file that I have stored in with my movies, the video runs perfectly normally when I use Gallery or Video Player to open it.

Any help is much appreciated.

Bart Beyers
  • 3,386
  • 1
  • 20
  • 20

2 Answers2

0
File file = new File(getFilePath());//file path of your video
                        MimeTypeMap map = MimeTypeMap.getSingleton();
                        String ext = MimeTypeMap.getFileExtensionFromUrl(file.getName());
                        String type = map.getMimeTypeFromExtension(ext);
                        if (type == null)
                            type = "*/*";
                        Uri uri = Uri.parse("www.google.com");
                        Intent type_intent = new Intent(Intent.ACTION_VIEW, uri);
                        Uri data = Uri.fromFile(file);
                        type_intent.setDataAndType(data, type);
                        startActivity(type_intent);
Bhanu Sharma
  • 5,135
  • 2
  • 24
  • 49
0

Make sure there will be no space in video name, otherwise it will not be played by android VideoView. If not solved then let me know.

Hradesh Kumar
  • 1,765
  • 15
  • 20