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 ?
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
来源:https://stackoverflow.com/questions/41869218/android-youtubeplayerview-shows-ad-word