I’m implementing a video player with ads. Eventually, playback is paused and some ads are shown, after the ads playback is resumed.
To implement this I’ve done a FrameLayout with a VideoView and another View to display the ads.
When the ads break is reached I do:
videoView.pause();
videoView.setVisibility(View.GONE);
adsView.setVisibility(View.VISIBLE):
//Play ads for X time
adsView.setVisibility(View.GONE);
videoView.setVisibility(View.VISIBLE);
videoView.play();
It’s fairly simple and it works fine in all devices I tried except the Nexus 7.
On the Nexus 7 when playback is resumed the video gets smaller and it doesn’t fill the whole screen. It only uses aprox 1/4 of the screen.
After a lot of hours investigating I realised this only happens when I change the visibility of the VideoView. If I comment the following line //videoView.setVisibility(View.GONE); the problem disappears but I can’t see the ads.
Some logs that may be relevant:
NvOsDebugPrintf BeginSequence 640x368
NvOsDebugPrintf pnvsi->nDecodeBuffers = 9
NvOsDebugPrintf Display Resolution : (640x360)
NvOsDebugPrintf Display Aspect Ratio : (128x360)
Display aspect ratio (128×360) should be the same as the display resolution (640×360) but it isn’t.
Any idea?
Thanks
Not sure of the cause but there seems to be measuring error (I think there are other reports of some measuring issues on n7). View.GONE causes the views to be relaid out to account of the space that is now free from the disappearing view.
As a work around, you can avoid being relaid out — try placing both views inside a RelativeLayout and have them completely overlap by setting fill_parent on width and height to both. Then you can use
setVisibility(View.INVISIBLE)which does not cause the widgets to resize.