use of com.winsonchiu.reader.utils.YouTubePlayerStateListener in project Reader by TheKeeperOfPie.
the class FragmentComments method loadYoutubeVideo.
private void loadYoutubeVideo(final String id, final int timeInMillis) {
if (youTubePlayer != null) {
toggleYouTubeVisibility(View.VISIBLE);
if (!id.equals(currentYouTubeId)) {
youTubePlayer.loadVideo(id);
currentYouTubeId = id;
}
return;
}
youTubeFragment = new YouTubePlayerSupportFragment();
layoutYouTube.setId(youTubeViewId);
getFragmentManager().beginTransaction().add(youTubeViewId, youTubeFragment, String.valueOf(youTubeViewId)).commit();
youTubeFragment.initialize(ApiKeys.YOUTUBE_API_KEY, new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player, boolean b) {
FragmentComments.this.youTubePlayer = player;
youTubePlayer.setManageAudioFocus(false);
youTubePlayer.setFullscreenControlFlags(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_SYSTEM_UI);
DisplayMetrics displayMetrics = getActivity().getResources().getDisplayMetrics();
boolean isLandscape = displayMetrics.widthPixels > displayMetrics.heightPixels;
if (isLandscape) {
youTubePlayer.setOnFullscreenListener(new YouTubePlayer.OnFullscreenListener() {
@Override
public void onFullscreen(boolean fullscreen) {
isFullscreen = fullscreen;
if (!fullscreen) {
releaseYouTube();
toggleYouTubeVisibility(View.GONE);
}
}
});
} else {
youTubePlayer.setOnFullscreenListener(new YouTubePlayer.OnFullscreenListener() {
@Override
public void onFullscreen(boolean fullscreen) {
isFullscreen = fullscreen;
}
});
}
youTubePlayer.setPlayerStateChangeListener(new YouTubePlayerStateListener(youTubePlayer, timeInMillis, isLandscape));
toggleYouTubeVisibility(View.VISIBLE);
youTubePlayer.loadVideo(id);
currentYouTubeId = id;
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
}
});
}
Aggregations