使用VideoView播放App中的资源文件
时间:2021-04-02 09:44:57|栏目:Android代码|点击: 次
本文实例为大家分享了使用VideoView播放App中资源文件的具体代码,供大家参考,具体内容如下
布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<VideoView
android:id="@+id/vv_video"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
先在res下新建一个文件夹raw,然后将视频复制到该文件夹下面。
具体实现代码
public class VideoActivity extends Activity{
VideoView videoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
initView();
}
public void initView(){
videoView= (VideoView) findViewById(R.id.vv_video);
playVideo();
}
public void playVideo(){
//String file=Environment.getExternalStorageDirectory().getPath()+"/oppo.3gp";//oppo.3gp视频播放的名字
String uri = "android.resource://" + getPackageName() + "/" + R.raw.oppo;
videoView.setVideoURI(Uri.parse(uri));
MediaController mc = new MediaController(this);
//设置控制器 控制的是那一个videoview
mc.setAnchorView(videoView);
//设置videoview的控制器为mc
videoView.setMediaController(mc);
videoView.start();
}
}
上一篇:Android_RecyclerView实现上下滚动广告条实例(带图片)
栏 目:Android代码
下一篇:微信浏览器弹出框滑动时页面跟着滑动的实现代码(兼容Android和IOS端)
本文地址:http://www.codeinn.net/misctech/92693.html






