0

I'm trying to play a video in a VideoView and I'm failing miserably. I'm working in an Eclipse emulator and am half expecting it not to work there, but when I install my app on my Android phone (version 2.2.1) it also fails. The error message I get is "Cannot play video. Sorry, this video cannot be played." The video is in the Raw folder. Below is my code. parsedData[3].toString() is the name of the video (without the 3gp extension) which is being extracted from a database call. What am I doing wrong?

VideoView videoview = (VideoView) findViewById(R.id.videoView);
videoview.setMediaController(new MediaController(this));
String path = "android.resource://" + getPackageName() + "/R.raw/" + parsedData[3].toString();
videoview.setVideoURI(Uri.parse(path));
videoview.requestFocus();
Melanie
  • 3,021
  • 6
  • 38
  • 56

2 Answers2

2

You can't play video in Raw folder. You should put your video (.3gp, mp4) in SD card of Emulator and play it. Because Emulator just supports playing videos in SD card ( not for Raw like audio). You can see this link: http://android-coding.blogspot.ca/2011/03/using-videoview-to-play-mp4-from-sdcard.html to understand how to play mp4 files in Emulator Android.

secretlm
  • 2,361
  • 2
  • 27
  • 38
  • 1
    OK, thanks, but what about on my phone? Why isn't it playing when I install my app on my phone? – Melanie Jun 12 '12 at 14:34
  • Also, I'm having problems pushing an image to my sdcard in my Emulator. See http://stackoverflow.com/questions/10841876/cant-push-file-to-sd-card-using-eclipse-emulator for a description. If you can help on this, too, that'd be great! – Melanie Jun 12 '12 at 14:46
2

You should play videos in SD card (both emulator and device). To push files (videos, audios, images) in Emulator you should see this link: http://www.streamhead.com/android-tutorial-sd-card/

or see this link to try play videos on the link: Trying to play video from raw folder (VideoView)

Community
  • 1
  • 1
secretlm
  • 2,361
  • 2
  • 27
  • 38
  • +1 for the link to what appears to be a solution for video in the raw folder – Chris Stratton Jun 12 '12 at 15:52
  • Thank you. I'm struggling to get the sdcard created in my emulator and an image pushed to it. But, while I'm dealing with that, let me ask you: is there no way to play an image that's part of an Android project? Does the image have to be on the sdcard? This would be a big problem for my app because my business model is that users will be able to buy different modules, each with their own videos. So, I'd like the videos to be included in the project, unless there's an easy way to copy them to the user's sdcard at install time... – Melanie Jun 12 '12 at 18:38
  • Of course, it can be. But using images, video like the part of an Android project, it isn't good for your application's performance if you have a lot of images, videos. I usually put images, videos on the server, and get them (by calling web services to access them in Android) in my application. – secretlm Jun 13 '12 at 12:45