Youtubeplayer - Navigation Bar Overlay
Solution 1:
So this is how went around the problem (this is still not a solution but its the closest I can get to).
So, I added an OnSystemUiChangeListener
in the onInitializationSuccess
of YoutubePlayerSupportFragment
(or YoutubePlayerFragment
).
(View) getView().getParent().setOnSystemUiVisibilityChangeListener();
provide an implemented object of OnSystemUiChangeListener
.
Override the method onSystemUiVisibilityChange()
like so:
@OverridepublicvoidonSystemUiVisibilityChange(int visibility) {
if (visibility == View.SYSTEM_UI_FLAG_VISIBLE) {
scheduleNavigationBarHide();
}
elseif (visibility == View.SYSTEM_UI_FLAG_HIDE_NAVIGATION || visibility == View.SYSTEM_UI_FLAG_LOW_PROFILE
|| visibility == View.SYSTEM_UI_FLAG_FULLSCREEN) {
if (navigationBarHandler != null) {
navigationBarHandler.cancel();
navigationBarHandler.purge();
navigationBarHandler = null;
}
}
}
Provide definition for the method scheduleNavigationBarHide().
privatevoidscheduleNavigationBarHide() {
if (navigationBarHandler != null) {
Log.d(TAG, "Canceling navigationBarHandler.");
navigationBarHandler.cancel();
navigationBarHandler.purge();
navigationBarHandler = null;
}
if (mContext != null && mContext instanceofJadooTVActivity) {
navigationBarHandler = newTimer();
navigationBarHandler.schedule(newTimerTask() {
publicvoidrun() {
((JadooTVActivity) mContext).runOnUiThread(newRunnable() {
@Overridepublicvoidrun() {
if (!isPlayerSqueezed) {
hideAsImmersiveNavigationBar(Config.context);
}
else {
Utils.showNavigationBar(Config.context);
}
}
});
}
}, 500);
}
}
So finally hideAsImmersiveNavigationBar()
as you might have guessed this works by making the Navigation Bar
temporarily immersive. Here's how
privatevoidhideAsImmersiveNavigationBar(Activity activity) {
if(activity != null)
{ ViewdecorView= activity.getWindow().getDecorView();
intuiOptions= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE;
decorView.setSystemUiVisibility(uiOptions);
}
}
Later when player has closed you might wanna bring back the Navigation Bar
. Change the UI Flags to int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE | View.SYSTEM_UI_FLAG_FULLSCREEN;
Finally a little disclaimer: I have provided a list of devices the application has been tested, I don't know if this will work on every devices. If you do find a device where the issue is persistent then feel free to comment. Also Immersive mode was added from API 19 so the solution will not work on any device before that, but I only had the issue on one device running API 21. All the older devices worked well. Also If/when the Navigation Bar
stays for 1 second, we still get the overlay error.
Solution 2:
change activity to full screen when youtube is fullscreen.
void toggleFullScreen(boolean goFullScreen){
if(goFullScreen){
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
}else{
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
yourView.requestLayout();
}
Post a Comment for "Youtubeplayer - Navigation Bar Overlay"