Android - MediaController of VideoView within dialog appears behind the dialog

android, android-videoview, dialog, mediacontroller

Solution

I suggest that you need to use an `Activity` instead of a `Dialog`. Set your `Activity` theme to emulate a `Dialog` in the manifest.

Example - AndroidManifest.xml:

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

Then, you will be able to display a `VideoView` as in the examples.

Problem

I have a `VideoView` inside a custom dialog, and I am creating a media controller for the `VideoView` on the fly and assigning it to the `VideoView` in the code, however the controller doesn't actually appear over the video - it appears behind the dialog! Any idea how to get the controller above the video? I created a static dialog helper class to help construct the custom dialogs: ``` 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; } } ``` So in my `Activity` i just have this to create my dialog: ``` Dialog videoDialog = DialogHelper.getVideoDialog(context, Uri.parse("http://commonsware.com/misc/test2.3gp"), true); videoDialog.show(); ```

Original source