ItGo.me Focus on IT Recommend

Home > android - Video playing in gallery but not app

android - Video playing in gallery but not app

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.

Recommend:video - is there a way to make VideoView keep playing in background on Android app

ideo stops.. is there a way to make it keep playing Whats the best way to make a video keep running in background Thanks in advance, Amitos80 android video streaming html5-video videoview
  asked Nov 6 '11 at 20:24 amitos80 40 17 1

android video videoview mediacontroller
edited Feb 7 '14 at 11:17 Bart Beyers 2,169 1 12 19 asked Feb 7 '14 at 10:59 user3283512 6 2

 | 

2 Answers
2

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);

answered Feb 7 '14 at 11:06 Bhanu Sharma 3,178 1 11 30

 | 

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.


answered Feb 7 '14 at 13:11 Hradesh Kumar 744 4 12      no I made sure I used underscores in the name so there are definitely no spaces –  user3283512 Feb 8 '14 at 0:03

 | 

Recommend:Playing video in videoview android

View(R.layout.activity_login_page); //initializing part introVideoView = (VideoView) findViewById(R.id.vvIntroVideo); try { introPlayer(); } catch (Exception e) { // TODO Auto-generated catch block

oriUlr:http://stackoverflow.com/questions/21625959/video-playing-in-gallery-but-not-app

------splitte line----------------------------