我想从我的资产或原始文件夹播放视频我的、我想、文件夹、原始

2023-09-12 23:49:04 作者:醉酒劍舞

我想打从我的资产或原始文件夹中的视频在我的Andr​​oid应用 使用 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.