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

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

本文介绍了我想从我的资产或原始文件夹播放视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打从我的资产或原始文件夹中的视频在我的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();
 

解决方案

有几件事情需要注意:

  1. 您必须复制视频到你的项目的 RES /生文件夹。
  2. 这必须是一个支持的格式(3GP,WMV,MP4),并命名为小写字母,数字,下划线和在它的文件名点: my_video_file.mp4
  3. 当您使用该资源在code,你将通过阵列生成的R静态参考 - 这将具有文件扩展名中删除: R.raw.my_video_file
  4. 在该活动类有一个辅助方法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 Androidusing VideoView I am getting the error as video cannot be playedplease 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:

  1. You must copy the video into your project's res/raw folder.
  2. 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
  3. 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
  4. 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.

这篇关于我想从我的资产或原始文件夹播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 13:41