开发者

Video won't play on second call

With the following cod开发者_如何学运维e in the onCreateDialog i open a Dialog which shows a video.

dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.video_dialog);

final VideoView videoView = (VideoView) dialog.findViewById(R.id.videoView);

videoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.test2));
videoView.setZOrderOnTop(true);
videoView.start();

This works great the first time I call it. but if I cancel the Dialog by pressing the back button and open that Dialog again the video doesn't start. The Dialog opens up but I can only see the black background of the Dialog.

I tried setting an OnCancelListener so i can make sure video is stoped and the dialog is not used again by doing the following

dialog.setOnCancelListener(new OnCancelListener() {
    @Override
    public void onCancel(DialogInterface dialog) {
    videoView.stopPlayback();
    //videoView.suspend();
    dialog = null;
}

Neither stopPlayback() nor suspend() did the trick.

Can anyone tell what may cause this problem?


You have to move your code in onPrepareDialog.The first time you run in the dialog is created so onCreateDialog is called but the second time the dialog is already created and only onPrepareDialog is called. Little more info about dialogs

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜