How to Play Videos in Android from Assets Folder or Raw Folder

Android: how to play video from assets?

Instead of accessing from assests,You must copy the video into your project's res/raw folder.
Create raw folder under res folder.
It must be in a supported format (3gp, wmv, mp4 ) and named with lower case, numerics, underscores and dots in its filename likewise:video_file.mp4.

VideoView view = (VideoView)findViewById(R.id.videoView);
String path = "android.resource://" + getPackageName() + "/" + R.raw.video_file;
view.setVideoURI(Uri.parse(path));
view.start();

How to load videos from assets folder? (to play them with VideoView)

I don't know how to load videos from the assets folder. But I know how to load them from the /res/raw/ folder:

String uriPath = "android.resource://yourapplicationpackage/raw/videofilenamewithoutextension";
Uri uri = Uri.parse(uriPath);
video.setVideoURI(uri);

Trying to play video from raw folder (VideoView)

I had the same problem.
This worked for me:

Uri video = Uri.parse("android.resource://com.pac.myapp/raw/master");

So as you see you have 3 parts of the uri: 1) "android.resource://" 2) "com.pac.myapp" 3) "/raw/master"

"master" is the name of your video



Related Topics



Leave a reply



Submit