Search in sources :

Example 1 with YouTubePlayerSupportFragment

use of com.google.android.youtube.player.YouTubePlayerSupportFragment 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) {
        }
    });
}
Also used : YouTubePlayer(com.google.android.youtube.player.YouTubePlayer) YouTubeInitializationResult(com.google.android.youtube.player.YouTubeInitializationResult) YouTubePlayerSupportFragment(com.google.android.youtube.player.YouTubePlayerSupportFragment) DisplayMetrics(android.util.DisplayMetrics) YouTubePlayerStateListener(com.winsonchiu.reader.utils.YouTubePlayerStateListener)

Example 2 with YouTubePlayerSupportFragment

use of com.google.android.youtube.player.YouTubePlayerSupportFragment in project DraggablePanel by pedrovgs.

the class YoutubeSampleActivity method initializeYoutubeFragment.

/**
   * Initialize the YouTubeSupportFrament attached as top fragment to the DraggablePanel widget and
   * reproduce the YouTube video represented with a YouTube url.
   */
private void initializeYoutubeFragment() {
    youtubeFragment = new YouTubePlayerSupportFragment();
    youtubeFragment.initialize(YOUTUBE_API_KEY, new YouTubePlayer.OnInitializedListener() {

        @Override
        public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player, boolean wasRestored) {
            if (!wasRestored) {
                youtubePlayer = player;
                youtubePlayer.loadVideo(VIDEO_KEY);
                youtubePlayer.setShowFullscreenButton(true);
            }
        }

        @Override
        public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult error) {
        }
    });
}
Also used : YouTubePlayer(com.google.android.youtube.player.YouTubePlayer) YouTubeInitializationResult(com.google.android.youtube.player.YouTubeInitializationResult) YouTubePlayerSupportFragment(com.google.android.youtube.player.YouTubePlayerSupportFragment)

Aggregations

YouTubeInitializationResult (com.google.android.youtube.player.YouTubeInitializationResult)2 YouTubePlayer (com.google.android.youtube.player.YouTubePlayer)2 YouTubePlayerSupportFragment (com.google.android.youtube.player.YouTubePlayerSupportFragment)2 DisplayMetrics (android.util.DisplayMetrics)1 YouTubePlayerStateListener (com.winsonchiu.reader.utils.YouTubePlayerStateListener)1