YoutubePlayer-导航栏叠加 [英] YoutubePlayer - Navigation Bar Overlay

查看:82
本文介绍了YoutubePlayer-导航栏叠加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中使用YoutubePlayerSupportFragment.我正在添加YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT标志.来自文档我知道我的播放器从全屏退出后不会重新缓冲,但是现在我必须处理操作栏和导航栏.但是文档没有说明或指出如何处理这些情况.

I am using YoutubePlayerSupportFragment in my application. I am adding YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT flag. From the documentation I know my player won't rebuffer after exiting from full screen, but now I have to handle Action Bar and Navigation Bar. But the documentation doesn't say or point to how I can handle these cases.

现在,我所面临的问题仅在华硕Nexus 7 OS 5.1.1中发生.我也有LG G2 D802 OS 4.4.2,Samsung Galaxy TAB GT P5113 OS 4.4.2和Samsung Galaxy Tab SM-T310 OS 4.2.2,它们不会引发重叠错误.在Log cat中,我收到以下消息.

Now the problem I am facing is so far only occurring in Asus Nexus 7 OS 5.1.1. I also have an 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 the Log cat 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's bottom edge. .

所以我知道导航栏中的问题.导航栏重叠在播放器顶部.

So I know the problem is in the Navigation Bar. Navigation Bar is overlaying on top of the Player.

我的问题是这些

  • 为什么在其他设备上没有得到相同的错误?
  • 如何处理系统导航栏,以便在全屏状态下(如果/当我想停止播放器(按回去)而不将其覆盖在播放器上时)仍能获得导航栏.

我尝试了侦听Click事件,但是在全屏模式下我什么也听不见,所以我在Activity中尝试了Overriding dispatchTouchEvent()并获得了自己的Click事件,但即使这样也不能帮助我摆脱困境时间导航栏(实际上是在时间之前).

I tried Listening for Click Events But in Full Screen Mode I can't get any so I tried Overriding dispatchTouchEvent() in the Activity and get a Click event my self but even that doesn't help me get rid of Navigation Bar in Time (before time actually).

我还尝试通过OnSystemUiVisibilityChangeListener侦听系统UI的更改,并在其中隐藏导航栏(但再次隐藏导航栏也许还为时过早).

I also tried listening for System UI change via OnSystemUiVisibilityChangeListener and hiding navigation bar there (but again perhaps too early to hide navigation bar).

我已在Android清单文件中设置了android:theme="@style/Theme.AppCompat.NoActionBar",因此我真的不需要只隐藏导航栏上的操作/状态栏.

I have set android:theme="@style/Theme.AppCompat.NoActionBar" in android manifest file so I don't really need to hide the action/status bar just the navigation bar.

如果有人可以确认这是设备特定的问题,那将是很大的帮助.

Also if anyone can confirm it is device specific issue, it'll be a great help.

推荐答案

这就是解决问题的方法(这仍然不是解决方案,但它是我能找到的最接近的解决方案).

So this is how went around the problem (this is still not a solution but its the closest I can get to).

因此,我在YoutubePlayerSupportFragment(或YoutubePlayerFragment)的onInitializationSuccess中添加了OnSystemUiChangeListener.

So, I added an OnSystemUiChangeListener in the onInitializationSuccess of YoutubePlayerSupportFragment (or 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;
        }
    }
}

提供方法scheduleNavigationBarHide()的定义.

Provide definition for the method scheduleNavigationBarHide().

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暂时浸入水中来实现的.这是

So finally hideAsImmersiveNavigationBar() as you might have guessed this works by making the Navigation Bar temporarily immersive. Here's how

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.将UI标志更改为int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE | View.SYSTEM_UI_FLAG_FULLSCREEN;

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;

最后一点免责声明:我提供了已测试应用程序的设备列表,我不知道这是否适用于所有设备.如果您确实找到问题持续存在的设备,请随时发表评论. API 19还添加了沉浸式模式,因此该解决方案在此之前无法在任何设备上运行,但是我只在运行API 21的一台设备上遇到了问题.所有较旧的设备都运行良好.此外,如果/当Navigation Bar停留1秒钟时,我们仍然会收到叠加错误.

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.

这篇关于YoutubePlayer-导航栏叠加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆