直接上代码:
java代码:
LayoutInflater inflater = LayoutInflater
.from(TeiHimeActivity.this);final View layout = inflater.inflate(R.layout.dialog_videoview,
null);
VideoView mVideoView = (VideoView) layout
.findViewById(R.id.sh_myvideoview);
mVideoView.setZOrderOnTop(true);
mVideoView.setVideoPath("/mnt/sdcard/daomeixiong.mp4");
//
final WindowManager wm = (WindowManager) getApplicationContext()
.getSystemService("window");
//
int width = wm.getDefaultDisplay().getWidth();
int height = wm.getDefaultDisplay().getHeight();
mVideoView.start();
WindowManager.LayoutParams wmParams = new WindowManager.LayoutParams();
wmParams.type = 2002; // 2002表示系统级窗口
wmParams.format = 1;
wmParams.flags = 40;
wmParams.width = width;
wmParams.height = height;
wm.addView(layout, wmParams);// 创建View
// 播放出错回调
mVideoView.setOnErrorListener(new OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
wm.removeView(layout);
return false;
}
});
// 播放完成回调
mVideoView.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
wm.removeView(layout);
}
});
布局文件R.layout.dialog_videoview
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white" >
<VideoView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/sh_myvideoview"
/>
</RelativeLayout>
谢谢观赏~