Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android VideoView: Video view is much darker in a dialog view

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();
                }
            });
like image 272
Jason Rogers Avatar asked Mar 09 '11 07:03

Jason Rogers


People also ask

What is video view in android?

android.widget.VideoView. Displays a video file. The VideoView class can load images from various sources (such as resources or content providers), takes care of computing its measurement from the video so that it can be used in any layout manager, and provides various display options such as scaling and tinting.


4 Answers

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

mVideoView.setZOrderOnTop(true);

to bring the VideoView to front, so that it does not get dimmed, but still everything behind the dialog will.

like image 162
spatialist Avatar answered Oct 17 '22 23:10

spatialist


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

WindowManager.LayoutParams a = dialog.getWindow().getAttributes();
a.dimAmount = 0;
dialog.getWindow().setAttributes(a);

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)

like image 20
Jason Rogers Avatar answered Oct 17 '22 22:10

Jason Rogers


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.

getDialog().getWindow().getDecorView().
            findViewById(android.R.id.content).
            setBackgroundResource(android.R.drawable.screen_background_dark_transparent);
like image 41
Sreegth Avatar answered Oct 17 '22 23:10

Sreegth


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.

like image 33
s4ur0n Avatar answered Oct 17 '22 23:10

s4ur0n