How To Load Videos From Assets Folder? (to Play Them With Videoview)
I need to open a mp4 video from the assets folder and play it with VideoView. I tryed with these two options, but none of them works.... mVideoView.setVideoPath('file:///android_as
Solution 1:
I don't know how to load videos from the assets folder. But I know how to load them from the /res/raw/ folder:
StringuriPath="android.resource://yourapplicationpackage/raw/videofilenamewithoutextension";
Uriuri= Uri.parse(uriPath);
video.setVideoURI(uri);
Solution 2:
Playing the .mp4 file from \assets
is not possible, you must load it from \raw
folder.
Example:
if you have a file called video.mp4
inside the /raw
folder:
StringfileName="android.resource://"+ getPackageName() + "/raw/video";
VideoViewvv= (VideoView) this.findViewById(R.id.surface);
vv.setVideoURI(Uri.parse(fileName));
vv.start();
Solution 3:
EDITED
Try:
this.setContentView(R.layout.videoview);
mVideoView = (VideoView) this.findViewById(R.id.surface_view);
SurfaceHolderholder= mVideoView.getHolder();
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
MediaPlayerplayer=newMediaPlayer();
player.setDisplay(holder);
AssetFileDescriptor afd;
try {
afd = getAssets().openFd("v.mp4");
player.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(), afd.getLength());
player.prepareAsync();
player.setOnPreparedListener(newOnPreparedListener() {
@OverridepublicvoidonPrepared(MediaPlayer mp) {
mp.start();
}
});
} catch (Exception e) { e.printStackTrace();}
Post a Comment for "How To Load Videos From Assets Folder? (to Play Them With Videoview)"