Android简单使用VideoView+MediaController播放本地视频
作者:互联网
在res/目录下创建raw文件夹
MediaActivity.java
VideoView videoView = (VideoView)findViewById(R.id.videoView);
videoView.setMediaController(new MediaController(this));
// 设置视频源播放res/raw中的文件,文件名小写字母,格式: 3gp,mp4等,flv的不一定支持;
Uri rawUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.video02);
videoView.setVideoURI(rawUri);
videoView.start();
videoView.requestFocus();
activity.media.java
<?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">
<!--在VideoView外面套一层,用于限制MediaController在视频下边显示-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="300dp">
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
标签:MediaController,java,res,VideoView,raw,Android,videoView 来源: https://blog.csdn.net/Bosom_Friend/article/details/122373965