Hi all I have a problem with embedding a video view inside a dialog view
everything works fine except that the video displayed in the Dialog is much darker that if displayed in the rest of the activity
any ideas ?
here is some code
button1main.setOnClickListener(new OnClickListener() {
public VideoView videoView = null;
@Override
public void onClick(View v) {
//set up dialog
Dialog dialog = new Dialog(CustomDialog.this);
dialog.setContentView(R.layout.maindialog);
//dialog.setTitle("This is my custom dialog box");
dialog.setCancelable(true);
this.videoView = (VideoView) dialog.findViewById(R.id.video);
VideoPlayer vp = new VideoPlayer(this.videoView, null);
vp.playVideo();
//set up button
Button button = (Button) dialog.findViewById(R.id.Button01);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
//now that the dialog is set up, it's time to show it
dialog.show();
}
});
it seems that the
VideoView
gets dimmed because it is created behind the window. Jason Rogers solution works but means that the area behind the dialog will not get dimmed.I used
to bring the
VideoView
to front, so that it does not get dimmed, but still everything behind the dialog will.one more simple solution is add this to your styles, it will disable dim background.
I tried this fix and found it working.
Use following style on the dialog for removing the default dim behavior of the Window, so the VideoView / SurfaceView doesn't have the dim behavior as well.
<item name="android:backgroundDimEnabled">false</item>
Then in the dialog's onViewCreated method, set the background programmatically to achieve the Dim effect.
While the spatialist suggested works, the only problem there is if you ever want to setZOrderOnTop to false after setting it to true. It seems once set it is always true.
I recently came across the same issue (videoview in a dialog) and the way I fixed it, reluctantly, was to clear FLAG_DIM_BEHIND so the video is "bright". I got the dim effect by just making my dialog fullscreen and setting the background to a 'dim color' if that makes any sense.
More Info: With regards to the media controller, I could not find any way of bringing it to top of the dialog. I ended up creating a custom media controls layout and put it on top of the video view. It's important in this context as calling setZOrderOnTop would prevent you from putting the media controller on top of the video view.
Hope this made sense and helps someone.
I actually found the solution to this (or at least in my case)
it seems its a bug from android where the Video View is created behind the Dialog and when the Dialog opens it dims the background views including the video
the "quick fix" I applied is
they might be a solution better solution like passing the context of the Dialog box instead of using the same context for creating the Dialog and the Video View (I'll check later if I get sone time)