这里我是用VideoView来进行播放视频
注意:请事先在手机的SD卡的根目录下放一个名为movie.mp4的视频文件,因为等下我就是读取这个文件的路径并进行播放,暂停和重新播放的操作。
首先我们在AndroidManifest.xml文件中添加以下内容:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
MainActivity的布局文件代码如下:
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/play"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="播放"
android:textSize="20sp" />
<Button
android:id=