欢迎来到代码驿站!

Android代码

当前位置:首页 > 移动开发 > Android代码

使用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端)

本文标题:使用VideoView播放App中的资源文件

本文地址:http://www.codeinn.net/misctech/92693.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有