Android - Views overlaid on the last frame of a fullscreen video don't redraw properly when turning the screen on and off
Asked Answered
S

3

19

I have a video that plays in portrait mode. At the end of the video, I need to display some views over it. This works fine so far.

I am however, having a problem where views that are over the last frame of a video don't redraw properly when coming back to the activity after turning the screen off, then on again, then unlocking the screen.

What i'm observing is that when the screen comes back on and I unlock. My video and images are first rendered outside of fullscreen mode (with the status bar still showing) then the screen will go into fullscreen mode shifting all of the views up and causing artifacting.

It seems like the views are being shifted out of their view bounds by the transition to fullscreen after they are rendered.

I'm really stumped as to how to prevent this from happening.

Here is the sandbox project on github to avoid making this a post full of code.

The basic setup for the project is this:

Fragment activity has a video view and a button view on it's layout. It then adds a fragment into a contentView container. The contentView fades in 1 second prior to the end of video playback.

Everything works smoothly and the problem is with returning back to the app after powering the screen on and off.

Also, sometimes the video will just drop out entirely, leaving the views sitting atop a black background.

Thanks in advance for any help you can provide.

proper rendering of views over video

Here's the artifacting that happens when you turn the screen off, back on, and unlock. Note that I had to take a picture of it. On DDMS the screenshot tool sees the images properly.

artifacted image

Solemnize answered 8/2, 2012 at 0:6 Comment(0)
C
3

rather than prevent the screen from turning off, you can opt in to receive an event when the user unlocks the keyguard after waking the phone.

At this point, it might be a good idea to call View.invalidate on both of your views, this should cause a redraw. The draw chain is very flaky while the lock screen is up, because your app is technically visible, just under the lock screen.

    registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context ctx, Intent intent) {
            if(intent.getAction().equals(Intent.ACTION_USER_PRESENT))

        }
    }, new IntentFilter(Intent.ACTION_USER_PRESENT));
Chastise answered 4/4, 2012 at 21:56 Comment(2)
Thanks Colin. This definitely helped, i haven't figured out how to fix it yet but your suggestion illustrates the problem. The issue is that onResume is called while you're viewing the lock screen. On the lock screen the status bar is visible which causes improper drawing. Receiving the user persent intent will help correct the problem. Only issue now is that calling invalidate on the views seemed to have no effect. But that should be the easy part. Thanks again!Solemnize
np! Calling invalidate can be tricky too, some views will want to invalidate from a cache or a previous dirtyregion. You can try to call invalidate with a Rect, or requestLayout should also kill most view caches.Chastise
B
0

It looks like the overlay layout was shifted by controller bar.
Don't you think it was affected by controller (play/pause/ff/rew + progress) area?

Beekman answered 13/2, 2012 at 4:59 Comment(1)
hi JonA. Not sure what you mean. I don't have any controllers set for this mediaplayer instance. But is there something else I should do to make sure the controller bar doesn't interfere?Solemnize
T
0

there may be a way to prevent the screen going off in 1st place as this would be good resolving your re draw issues, hope this helps.

To answered 14/3, 2012 at 12:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.