android YouTubePlayerView shows “Ad” word

我只是一个虾纸丫 提交于 2019-12-08 06:40:01

问题


We've been using YouTubePlayerView with YouTubePlayer in our app for some time and recently I noticed we start seeing the word "Ad" on the bottom left of the view.

Double checking it I am certain this comes from YouTubePlayerView and not from the player or from any other layout part related to our app.

Our initialization of the player is straightforward, we're doing this:

        mYoutubePlayer.setShowFullscreenButton(false);
        mYoutubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.MINIMAL);
        mYoutubePlayer.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_SYSTEM_UI);
        mYoutubePlayer.setPlayerStateChangeListener(playerStateChangeListener);
        mYoutubePlayer.setPlaybackEventListener(playbackListener);

Here's a screenshot so you can see what I mean:

Any idea how I can get rid of this Ad word ?


回答1:


I think it's such kind a bug of this player. Try this one hack to hide it. Or change PlayerStyle to CHROMELESS and implement your own controls

(((ViewGroup)((ViewGroup)((ViewGroup)((ViewGroup)((ViewGroup)
        fragment.getView()).getChildAt(0)).getChildAt(0)).getChildAt(5))
        .getChildAt(0)).getChildAt(1)).setVisibility(View.GONE);

Where fragment is instance of YouTubePlayerFragment




回答2:


The correct answer is the following ;)

public void removeFromYoutubePlayer(ViewGroup youtubePlayer, int... depths) {

    for (int i = 0; i < depths.length; i++) {

        youtubePlayer = (ViewGroup) youtubePlayer.getChildAt(depths[i]);

        if (i == depths.length - 1) {
            youtubePlayer.setVisibility(View.GONE);
        }
    }

}

And use this method in the following way

ViewGroup youtubePlayer = (ViewGroup) youTubePlayerFragment.getView();

int[] youtubeLogo = new int[] { 0, 0, 4, 0, 0, 3, 0, 1 }; // remove youtube logo

int[] adWord= new int[] { 0, 0, 5, 0, 1 }; // remove "ad" word

removeFromYoutubePlayer(youtubePlayer, adWord); // removed "ad" word


来源:https://stackoverflow.com/questions/41869218/android-youtubeplayerview-shows-ad-word

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!