Android Open Source - Android_Youtube_Sampler Playlist Video






From Project

Back to project page Android_Youtube_Sampler.

License

The source code is released under:

GNU General Public License

If you think the Android project Android_Youtube_Sampler listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.pgmacdesign.youtubebasics;
//from   w w w.ja va2 s  .co  m
import android.os.Bundle;

import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerSupportFragment;
import com.google.android.youtube.player.YouTubePlayerView;

//Plays a playlist of videos once inflated
public class PlaylistVideo extends YouTubePlayerSupportFragment {

  private String currentVideoID = "video_id";
  private YouTubePlayer activePlayer;

  public static PlaylistVideo newInstance(String url) {
    //Object of video fragment format
    PlaylistVideo playerYouTubeFrag = new PlaylistVideo();

    //Bundle to add details from the URL passed in
    Bundle bundle = new Bundle();
    bundle.putString("url", url);

    //Set the arguments into the bundle and then initiate it
    playerYouTubeFrag.setArguments(bundle);
    playerYouTubeFrag.init();

    return playerYouTubeFrag;
  }

  protected YouTubePlayer.Provider getYouTubePlayerProvider() {
    return (YouTubePlayerView) getActivity().findViewById(R.id.youtube_view);
  }

  //Initializes the youtube player
  private void init() {
    initialize(DeveloperKey.API_KEY, new YouTubePlayer.OnInitializedListener() {

      @Override
      public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player, boolean wasRestored) {
        activePlayer = player;
        activePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT);
        if (!wasRestored) {
          //Plays a playlist of videos
          activePlayer.loadPlaylist(getArguments().getString("url"));

        }
      }

      @Override
      public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
      }
    });
  }

  public void onYouTubeVideoPaused() {
    activePlayer.pause();
  }
}




Java Source Code List

com.pgmacdesign.youtubebasics.DeveloperKey.java
com.pgmacdesign.youtubebasics.InitialFragment.java
com.pgmacdesign.youtubebasics.MainActivity.java
com.pgmacdesign.youtubebasics.NavigationDrawerFragment.java
com.pgmacdesign.youtubebasics.OneVideo.java
com.pgmacdesign.youtubebasics.PlaylistVideo.java
com.pgmacdesign.youtubebasics.Splash.java