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.
Update
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();
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
final MediaPlayer player = new MediaPlayer();
player.setDisplay(holder);
player.setDataSource(getAssets().openFd(fileName).getFileDescriptor());
player.prepareAsync();
player.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();
}
});
Now I get a the following exception:
java.io.FileNotFoundException: 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.
MainCode
XML
PlayVideoActivity.java:
activity_play_video.xml:
where videocontainer of type videoview.
Try:
It sounds maybe like you have the same issue as i do. instead of using MP4, is 3GPP possible? i think i used like HandBrake or something as the video converter... you just need to make sure you have the right encoder, like H.264x or something. sorry for being a little vague, it's been a while. Also, if it's possible, don't bother worrying about android 2.1 anymore, and also, something things just WILL NOT WORK IN EMULATOR. so if it works on a lot of devices, then just assume it works (especially with different manufacurers)
here, you can read my problem and how i solved the issue (after a long time and no one had an answer). i explained in a lot more detail here: android media player not working
Use the
MediaPlayer
API and the sample code.Put the media file in
raw
folder.Get the
file descriptor
to the file.mediaplayer.setDataSource(fd,offset,length);
- its a three argument constructor.Then when
onPreared
,mediaplayer.start();