YoutubePlayer - Overlay Navigation Bar

I use YoutubePlayerSupportFragmentin my application. I am adding a flag YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT. From the documentation I know that my player will not back off after exiting full-screen mode, but now I need to process the action bar and navigation bar. But the documentation does not say or indicate how I can handle these cases.

Now the problem that I encountered so far only occurs in Asus Nexus 7 OS 5.1.1. I also have LG G2 D802 OS 4.4.2, Samsung Galaxy TAB GT P5113 OS 4.4.2 and Samsung Galaxy Tab SM-T310 OS 4.2.2, and they do not throw Overlay Error. In Log, I get the following message.

03-09 15:54:39.760  11203-11203/com.jadoo.jadooplus W/YouTubeAndroidPlayerAPI﹕ 
YouTube video playback stopped due to unauthorized overlay on top of player. 
The YouTubePlayerView is obscured by android.view.View{c067400 V.ED.... ........ 0,736-1280,800 #1020030 android:id/navigationBarBackground}.
Top edge 24 px above YouTubePlayerView bottom edge. .

So, I know that the problem is in the navigation bar. The navigation bar is overlaid on top of the player.

My questions are

  • Why am I not getting the same error on other devices?
  • How can I handle the navigation bar on the system, so when I am in full screen mode, I can still get the navigation bar if / when I want to stop the player (on the remote control) without overlaying it on the player.

I tried listening for click events, but in full screen mode I can’t get them, so I tried Overriding dispatchTouchEvent()in Activity and received the Click event myself, but even this does not help me get rid of the Navigation bar in time (until the actual time).

I also tried to listen to the change in the user interface of the system through OnSystemUiVisibilityChangeListenerand hide the navigation bar there (but again, perhaps too soon to hide the navigation bar).

android:theme="@style/Theme.AppCompat.NoActionBar" android, action/status .

, - , , .

+1
2

( , , ).

, OnSystemUiChangeListener onInitializationSuccess YoutubePlayerSupportFragment ( YoutubePlayerFragment).

(View) getView().getParent().setOnSystemUiVisibilityChangeListener();

OnSystemUiChangeListener.

onSystemUiVisibilityChange() :

@Override
public void onSystemUiVisibilityChange(int visibility) {

    if (visibility == View.SYSTEM_UI_FLAG_VISIBLE) {
        scheduleNavigationBarHide();
    }
    else if (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;
        }
    }
}

NavigationBarHide().

private void scheduleNavigationBarHide() {


    if (navigationBarHandler != null) {
        Log.d(TAG, "Canceling navigationBarHandler.");
        navigationBarHandler.cancel();
        navigationBarHandler.purge();
        navigationBarHandler = null;
    }

    if (mContext != null && mContext instanceof JadooTVActivity) {
        navigationBarHandler = new Timer();

        navigationBarHandler.schedule(new TimerTask() {
            public void run() {
                ((JadooTVActivity) mContext).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        if (!isPlayerSqueezed) {
                            hideAsImmersiveNavigationBar(Config.context);
                        }
                        else {
                            Utils.showNavigationBar(Config.context);
                        }
                    }
                });
            }
        }, 500);
    }
}

, , hideAsImmersiveNavigationBar(), , Navigation Bar .

private void hideAsImmersiveNavigationBar(Activity activity) {

    if(activity != null)
    {   View decorView = activity.getWindow().getDecorView();

        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE;
        decorView.setSystemUiVisibility(uiOptions);
    }
}

, , Navigation Bar. int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE | View.SYSTEM_UI_FLAG_FULLSCREEN;

, : , , , . , , . Immersive API 19, - , API 21. . /, Navigation Bar 1 , .

0

, youtube .

 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(); 
}
0

Source: https://habr.com/ru/post/1599742/


All Articles