Monday, July 1, 2013

Load specified YouTube playlist

To load specified YouTube playlist in YouTube Android Player, simple call cuePlaylist(PlayList_ID) method of YouTubePlayer object, instead of cueVideo(VIDEO_ID) method.

Load specified YouTube playlist

Modify onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasRestored) method in MainActivity.java from last exercise "Example to use YouTubePlayerFragment of YouTube Android Player API".

 public static final String PlayList_ID = "PLP7qPet500dfglA7FFTxBmB_snxCaMHDJ";

 @Override
 public void onInitializationSuccess(Provider provider, YouTubePlayer player,
   boolean wasRestored) {
  
  youTubePlayer = player;
  
  Toast.makeText(getApplicationContext(), 
    "YouTubePlayer.onInitializationSuccess()", 
    Toast.LENGTH_LONG).show();
  
  youTubePlayer.setPlayerStateChangeListener(myPlayerStateChangeListener);
  youTubePlayer.setPlaybackEventListener(myPlaybackEventListener);
  
  if (!wasRestored) {
   //player.cueVideo(VIDEO_ID);
   player.cuePlaylist(PlayList_ID);
  }

 }


download filesDownload the files.

Download APK to try on your device.



The tutorial: YouTube Android Player API step-by-step

2 comments:

Unknown said...

how can I display all the videos in a PLAYLIST_ID LISTVIEW?

Unknown said...

Hi Thank you so much for sharing this useful stuff, I am working on it to get full benefit of playing Youtube Playlist, I just want to refresh Youtube player view with the one (youtube video) I have tapped in a List, but whenever I do tap on any of the list item not able to reload youtube video with tapped one.

So How can I change Youtube Video in a Youtube Player, I have written complete code, please visit: http://stackoverflow.com/questions/34017783/how-to-refresh-youtube-player-view-onitemclicklistener-in-a-listview