我在自定义对话框中有一个 VideoView。第一次显示 Dialog 时,视频可以正确播放,但如果 Dialog 被关闭然后再次加载,则视频不会播放,并且对话框只是黑屏。
这是我用来创建 Dialog 的代码:
Dialog d;
protected Dialog onCreateDialog(int id) {
switch(id) {
case DIALOG_VIDEO:
AlertDialog.Builder builder;
LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.video,null);
final VideoView vv = (VideoView)layout.findViewById(R.id.vv);
vv.setMediaController(new MediaController(this));
vv.setVideoURI(path);
vv.setZOrderOnTop(true);
vv.requestFocus();
vv.start();
builder = new AlertDialog.Builder(this);
builder.setView(layout);
d = builder.create();
d.setOnDismissListener(new DialogInterface.OnDismissListener() {
public void onDismiss(DialogInterface dialog) {
VideoView vv = (VideoView)d.findViewById(R.id.vv);
vv.stopPlayback();
vv.clearFocus();
}
});
break;
default:
d = null;
}
return d;
}
我究竟做错了什么 ?
感谢您的宝贵时间,并为我糟糕的英语感到抱歉。