How to play MP4 videos stored on assets folder on

2019-08-19 05:43发布

问题:

Ineed to play a short MP4 video on my android app I'm searching info about how to load mp4 videos but i can't find the way to do it on Android 1.5. My app sould be compatible from Android 1.5 to 4.0

I tryed with a lot of tutorials from google, but none of them works. For example, now i'm trying with the VideoViewDemo from android developers: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/media/VideoViewDemo.html

I have a video on my ASSETS folder, and i just need to play the video, only this. I can not believe that doesn't exists a simple and quick way to do it.

Please, if someone knows how to do it i will apreciate your help a lot.

Thanks

回答1:

You could put the video in the raw folder instead and construct a URI like this:

android.resource://[package]/[resource_id]
android.resource://[package]/[res type]/[res name]

For example:

Uri videoUri = Uri.parse("android:resource://com.my.package/"+R.raw.myVideo);
mVideoView.setVideoURI(videoUri);


回答2:

Have a look at page 314 of Mark's Busy Coder's guide to Android: http://commonsware.com/Android/Android-1_0-CC.pdf

There is an example there on how to get something from the asset folder.

Also, make sure that the codec is H.264 (not H.264 AVC). I don't think AVC was supported in 1.5. See: http://developer.android.com/guide/appendix/media-formats.html

Happy coding!



标签: android mp4