1)XML布局
<VideoView>控件的使用:
在布局的时候,VideoView要使用一个控件包裹起来,我这里使用的是id= Video_play_quan的RelativeLayout控件。
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/Video_play_quan"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
</RelativeLayout>
2)java代码实现
public void
playVideo(String path){
// String path =Environment.getExternalStorageDirectory().getPath() + File.separator +"test.mp4";
videoView.setVideoURI(Uri.parse(path));
MediaController mctrl = new MediaController(this);
videoView.setMediaController(mctrl);
RelativeLayout.LayoutParamslayoutParams = new
RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
videoView.setLayoutParams(layoutParams);
videoView.start();
videoView.requestFocus();
}