1、布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".bank_4.SP_01Activity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#0099CC"
android:gravity="center"
android:padding="5dp"
android:text="视频播放"
android:textColor="@android:color/black"
android:textSize="20dp" />
<ImageView
android:id="@+id/back_fh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/back" />
</RelativeLayout>
<VideoView
android:id="@+id/video"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
2、Activity文件
public class SP_01Activity extends AppCompatActivity {
private ImageView backFh;
private VideoView video;
private int[] lj = {R.raw.mv3, R.raw.mv3, R.raw.mv3, R.raw.mv3, R.raw.mv3};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_s_p_01);
init();
backFh.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SP_01Activity.this.finish();
}
});
Intent it = getIntent();
int id = it.getIntExtra("id", 0);
video.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + lj[id]));
MediaController controller = new MediaController(SP_01Activity.this);
video.setMediaController(controller);
video.start();
}
private void init() {
backFh = (ImageView) findViewById(R.id.back_fh);
video = (VideoView) findViewById(R.id.video);
}
}
3、注意
一、不加MediaController时
二、加MediaController时
可以暂停视频,查看进度条