对话框后面的对话框中显示的是VideoView的MediaController

前端之家收集整理的这篇文章主要介绍了对话框后面的对话框中显示的是VideoView的MediaController前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在自定义对话框中有一个VideoView,我正在为VideoView立即创建一个媒体控制器,并将其分配给代码中的VideoView,但控制器实际上并不会出现在视频中 – 它出现在对话框后面!任何想法如何让控制器上面的视频?

我创建了一个静态对话助手类来帮助构建自定义对话框:

public class DialogHelper {

    public static Dialog getVideoDialog(Context context,Uri videoLocation,boolean autoplay) {
        final Dialog dialog = getBaseDialog(context,true,R.layout.dialog_video);

        ((Activity)context).getWindow().setFormat(PixelFormat.TRANSLUCENT);
        final VideoView videoHolder = (VideoView) dialog.findViewById(R.id.video_view);
        videoHolder.setVideoURI(videoLocation);
        //videoHolder.setRotation(90);
        MediaController mediaController =  new MediaController(context);
        videoHolder.setMediaController(mediaController);
        mediaController.setAnchorView(videoHolder);
        videoHolder.requestFocus();
        if(autoplay) {
            videoHolder.start();
        }
        videoHolder.setOnCompletionListener(new OnCompletionListener() {

            @Override
            public void onCompletion(MediaPlayer mp) {
                dialog.dismiss();

            }
        });
        return dialog;
    }


    /**
     * Creates a simple dialog Box with as many buttons as you want
     * @param context The context of the dialog
     * @param cancelable whether the dialog can be closed/cancelled by the user
     * @param layoutResID the resource id of the layout you want within the dialog
     * 
     * @return the dialog
     */
    public static Dialog getBaseDialog(Context context,boolean cancelable,int layoutResID) {
        Dialog dialog = new Dialog(context,R.style.Theme_PopUpDialog);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setCancelable(cancelable);
        dialog.setCanceledOnTouchOutside(cancelable);
        dialog.setContentView(layoutResID);

        return dialog;
    }
}

所以在我的活动中,我只需要创建我的对话框:

Dialog videoDialog = DialogHelper.getVideoDialog(context,Uri.parse("http://commonsware.com/misc/test2.3gp"),true);
videoDialog.show();

解决方法

我建议您需要使用活动而不是对话框.设置您的活动主题以模拟清单中的对话框.

示例 – AndroidManifest.xml:

android:theme="@android:style/Theme.Dialog"

然后,您可以像示例中一样显示VideoView.

原文链接:/android/313467.html

猜你在找的Android相关文章