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

No comments:

Post a Comment