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_asset/videos.mp4"); mVideoView.requestFocus(); mVideoView.start();
and...
String uriPath = "file:///android_asset/videos.mp4"; Uri uri = Uri.parse(uriPath); mVideoView.setVideoURI(uri); mVideoView.requestFocus(); mVideoView.start();
These options didn't works, but if I try to open the video from the SDCARD it works perfectly, then, the problem is when I'm trying to load the video from the assets folder.
What I'm doing wrong?
thanks
Right click on the assets folder, select New >> file (myText. txt) and your text.
Step 1: To create an asset folder in Android studio open your project in Android mode first as shown in the below image. Step 2: Go to the app > right-click > New > Folder > Asset Folder and create the asset folder. Step 3: Android Studio will open a dialog box. Keep all the settings default.
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);
\assets
is not possible, you must load it from \raw
folder.Example:
if you have a file called video.mp4
inside the /raw
folder:
String fileName = "android.resource://"+ getPackageName() + "/raw/video"; VideoView vv = (VideoView) this.findViewById(R.id.surface); vv.setVideoURI(Uri.parse(fileName)); vv.start();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With