Android视频播放器开发
第一个播放器开发的实例,是通过VideoView+MediaController的方式实现的
主要实现了视频播放、暂停、快进、快退的功能
创建项目的名称为VideoView,建立类名为MyVideoView
一、项目的布局写法
代码中注释的部分记得去掉
注:横竖屏切换时会导致重走生命周期,为了避免这种情况,在在AndroidManifest中配置
<activity android:name=".MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize">
除此之外还需要在AndroidManifest中添加网络权限和sd卡权限
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
在activity_main.xml中添加视图布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.eddie.videoview.MainActivity">
<RelativeLayout
android:id="@+id/rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
//控制视频大小
<com.example.eddie.videoview.MyVideoView
android:id="@+