我想打从我的资产或原始文件夹中的视频在我的Android应用
使用 VideoView
我收到错误的视频无法播放
请谁能给我一个解决方案。
下面是code我用
VideoView VD =(VideoView)findViewById(R.id.Video);
开放的我们的uri = Uri.parse(android.resource:+ R.raw.video);
的MediaController MC =新的MediaController(本);
vd.setMediaController(MC);
vd.setVideoURI(URI);
vd.start();
解决方案
有几件事情需要注意:
您必须复制视频到你的项目的 RES /生文件夹。 这必须是一个支持的格式(3GP,WMV,MP4),并命名为小写字母,数字,下划线和在它的文件名点: my_video_file.mp4 当您使用该资源在code,你将通过阵列生成的R静态参考 - 这将具有文件扩展名中删除: R.raw.my_video_file 在该活动类有一个辅助方法getPackageName(),它可以构建正确的URI您的视频时,可以使用您的code。 VideoView VV =(VideoView)this.findViewById(R.id.videoView)
串的uri =android.resource://+ getPackageName()+/+ R.raw.my_video_file;
vv.setVideoURI(Uri.parse(URI));
vv.start();
有更多这方面的信息,here.
I want to play a video from my assets or raw folder in my app in Android
using VideoView
I am getting the error as video cannot be played
please anyone give me a solution.
Here is the code I used
VideoView vd = (VideoView)findViewById(R.id.Video);
Uri uri = Uri.parse("android.resource:" + R.raw.video);
MediaController mc = new MediaController(this);
vd.setMediaController(mc);
vd.setVideoURI(uri);
vd.start();
解决方案
A few things to note:
You must copy the video into your project's res/raw folder. It must be in a supported format (3gp, wmv, mp4 ) and named with lower case, numerics, underscores and dots in its filename: my_video_file.mp4 When you work with this resource in code, you will reference through the generated R statics - it will have the file extension removed: R.raw.my_video_file The Activity class has a helper method getPackageName() which can be used by your code when constructing the correct URI to your video.
VideoView vv = (VideoView)this.findViewById(R.id.videoView)
String uri = "android.resource://" + getPackageName() + "/" + R.raw.my_video_file;
vv.setVideoURI(Uri.parse(uri));
vv.start();
There is more information on this here.
上一篇:在web视图Android上使用navigator.geolocation.getCurrentPosition 2.0+(PhoneGap的相关)视图、navigator、Android、web