Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to play videos in android from assets folder or raw folder?
    primarykey
    data
    text
    <p>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?</p> <p>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. </p> <p>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.</p> <p><strong>Update</strong></p> <p>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:</p> <pre><code>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(); } }); </code></pre> <p>Now I get a the following exception: </p> <pre><code>java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed </code></pre> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload