1、这两种方法经常被使用播放视频,一般人喜欢使用Videoview控件因为功能都有自带的减少代码量,但是SurfaceView也在用,所以分享两种方法。执行效果如下:
第一种方法:使用SurfaceView+MediaPlayer+SeekBar控件完成
01、xml的布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.android_playmusic.MainActivity">
<SeekBar
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="@+id/sb_main_SeekBar"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height=