简单视频播放器的使用
一、简单使用videoView和MediaController实现播放控制
1、添加需要的权限
2、设置布局
android:id="@+id/main_video"
android:layout_width="match_parent"
android:layout_height="240dp"
/>
3、实例化VideoView
VideoView videoView = (VideoView) findViewById(R.id.main_video);
MediaController controller = new MediaController(this);//实例化控制器
// String path = Environment.getExternalStorageDirectory().getAbsolutePath()+"jiaoxue.mp4";
/**
* 本地播放
*/
// videoView.setVideoPath("path");
/**
* 网络播放
*/
videoView.setVideoURI(Uri.parse("http://192.168.1.109:8080/video/jiaoxue.mp4"));
/**
* 将控制器和播放器进行互相关联
*/
controller.setMediaPlayer(videoView);
videoView.setMediaController(controller);
二、自定义播放器 (贴上源码)
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.zzj.myeasyvideoplaydemo.MainActivity">
android:layout_width="match_parent"
android:layout_height="240dp">
android:id="@+id/main_video"
android:layout_width="match_parent"
android:layout_height="240dp"
/>
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="vertical"
android:layout_alignParentBottom="true"
>
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_marginLeft="-20dp"
android:layout_marginRight="-20dp"
android:max="100"
android:indeterminate="false"
android:progress="20"
/>
android:gravity="center_vertical"
android:background="#101010"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
android:id="@+id/play_pasue_image"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@mipmap/video_play_