android YouTubePlayerView shows “Ad” word

左心房为你撑大大i 提交于 2019-12-06 19:15:28

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

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