How to play videos in android from assets folder or raw folder?


I am trying to play a video in android emulator I have the video in my assets folder as well as the raw folder But after doing some research still i cant play video in my emulator i am working on android 2.1 My video format is mp4 so i don't think that should be a problem Could anyone just give me an example code so that i can understand a bit more?

The problem is that the VideoView that I need to display the Video will take only a URI or a File path to point to the Video.

If I save the video in the raw or assets folder I can only get an input stream or a file descriptor and it seems nothing of that can be used to initialize the VideoView.


I took a closer look at the MediaPlayer example and tried to start a MediaPlayer with a FileDescriptor to the assets files as in the code below:

SurfaceView videoView = (SurfaceView) findViewById(gettingStarted)
SurfaceHolder holder = videoView.getHolder();
final MediaPlayer player = new MediaPlayer();

player.setOnPreparedListener(new OnPreparedListener() {

   public void onPrepared(MediaPlayer mp) {

Now I get a the following exception: This file can not be opened as a file descriptor; it is probably compressed

It seems there is no other way then copying the file to the sdcard on startup and that seems like a waste of time and memory.

8/19/2010 12:31:50 PM

## Perfectly Working since Android 1.6 ##

VideoView videoHolder = new VideoView(this);
//if you want the controls to appear
videoHolder.setMediaController(new MediaController(this));
Uri video = Uri.parse("android.resource://" + getPackageName() + "/" 
+ R.raw.your_raw_file); //do not add any extension
//if your file is named sherif.mp4 and placed in /raw
//use R.raw.sherif

## Check complete tutorial ##

6/19/2012 12:45:39 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow