官方文档: https://developer.android.google.cn/reference/android/widget/VideoView

运行截图: 

/** * 亲测以下直播源均可用 * CCTV1高清:http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8 * CCTV3高清:http://ivi.bupt.edu.cn/hls/cctv3hd.m3u8 * CCTV5+高清:http://ivi.bupt.edu.cn/hls/cctv5phd.m3u8 * CCTV6高清:http://ivi.bupt.edu.cn/hls/cctv6hd.m3u8 */

主布局文件:

<?xml version="1.0" encoding="utf-8"?>                

主类:

/** * 该Demo用于演示VideoView播放网络视频 */public class MainActivity extends AppCompatActivity implements View.OnClickListener {    private VideoView videoView;    private Button start;    private Button pause;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        init();        initVideoView();    }    private void initVideoView() {        videoView.setVideoPath("http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8");    }    private void init() {        videoView = findViewById(R.id.videoView);        start = findViewById(R.id.start);        pause = findViewById(R.id.pause);        start.setOnClickListener(this);        pause.setOnClickListener(this);    }    @Override    public void onClick(View v) {        switch (v.getId()) {            case R.id.start:                if (!videoView.isPlaying()) {                    videoView.start();                }                break;            case R.id.pause:                if (videoView.isPlaying()) {                    videoView.pause();                }                break;        }    }    @Override    protected void onDestroy() {        super.onDestroy();        if (videoView != null) {            videoView.suspend();        }    }}/** * 亲测以下直播均可用 * CCTV1高清:http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8 * CCTV3高清:http://ivi.bupt.edu.cn/hls/cctv3hd.m3u8 * CCTV5+高清:http://ivi.bupt.edu.cn/hls/cctv5phd.m3u8 * CCTV6高清:http://ivi.bupt.edu.cn/hls/cctv6hd.m3u8 */

不要忘记在Manifest.xml里添加网络权限:

    

更多相关文章

  1. Android开发便签3:TextView的自动检测文本中的超链接和自动补全
  2. Android(安卓)自定义Dialog 的使用
  3. Android(安卓)-- 在一个Activity开启另一个Activity 并 获取他的
  4. Android学习笔记(3)——Android(安卓)Demo演示
  5. Android开发:定制Activity的标题栏(Titlebar)
  6. android -------- ConstraintLayout 宽高比和偏移量比(三)
  7. 读取SIM卡信息
  8. android 自定义权限
  9. Android(安卓)DrawerLayout 使用

随机推荐

  1. 查看Android(安卓)各种API版本占据当前市
  2. 学习android无私的资源
  3. 敏捷软件测试的七个关键成功要素 Android
  4. Android判断手机号码是否是正确的手机号
  5. 【Android】 点击空白处隐藏(收起)键盘
  6. Android中日期时间格式转换
  7. android集成flutter
  8. Android(安卓)studio ndk 开发轻松两步就
  9. Android Repo 超时的解决方法
  10. 使用React-navigation时候 Android物理返