I am using the Android YouTube API samples to create a chromeless YouTube player in my app. I am having an issue that the buffering / loading progress bar carries on displaying over my video even after it has loaded and started playing. I can reproduce this in the FragmentDemoActivity
sample with a couple of small modifications:
public class FragmentDemoActivity extends AppCompatActivity implements YouTubePlayer.OnInitializedListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragments_demo);
YouTubePlayerFragment youTubePlayerFragment =
(YouTubePlayerFragment) getFragmentManager().findFragmentById(R.id.youtube_fragment);
youTubePlayerFragment.initialize(DeveloperKey.DEVELOPER_KEY, this);
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
boolean wasRestored) {
if (!wasRestored) {
player.setPlayerStyle(YouTubePlayer.PlayerStyle.CHROMELESS);
player.loadVideo("nCgQDjiotG0", 10);
}
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {}
}
I have changed FragmentDemoActivity
to inherit from AppCompatActivity
instead of YouTubeFailureRecoveryActivity
, as the documentation says is fine to do. I have also changed the player style to be chromeless in onInitializationSuccess
. Finally, I have changed cueVideo
to loadVideo
, just to trigger auto play.
This happens on multiple devices including Nexus 5X. I am using library version 1.2.2. No error is triggered in onInitializationFailure
.
The video starts playing after buffering. The player is chromeless. However the buffering spinner never disappears. Is this a bug, or am I doing something I am not allowed to do?
I encountered this too, it really looks like a bug. Here is how I managed to work around it.
In your
onInitializationSuccess
, set aPlaybackEventListener
on theplayer
. Override theonBuffering
and do something like this:The
findProgressBar
method, used as a fallback just in case the YouTube code changes:This solution works perfectly fine for me, enabling the
ProgressBar
when the player is buffering and disabling it when it's not.EDIT: If anyone using this solution discovers that this bug has been fixed or that the position of the
ProgressBar
has changed, please share so that I can edit my answer, thanks!