2

List youtube playlist from my playlist with ID PLSt1J_r1AmrzOUCGZ6sWNxvOePK4nOwIk into my android application but it is showing one video at a time but on want it to show the whole list of videos before I play any video.

My main activity code

public class MainActivity extends YouTubeBaseActivity implements 
    YouTubePlayer.OnInitializedListener{

    public static final String API_KEY = "AIzaSyCe6tORd9Ch4lx-9Ku5SQ476uS9OtZYsWA";
    public static final String VIDEO_ID = "o7VVHhK9zf0";
    public static final String PlayList_ID = "PLP7qPet500dfglA7FFTxBmB_snxCaMHDJ";

    private YouTubePlayer youTubePlayer;
    private YouTubePlayerFragment youTubePlayerFragment;
    private TextView textVideoLog;
    private Button btnViewFullScreen;

    private static final int RQS_ErrorDialog = 1;

    String log = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        youTubePlayerFragment = (YouTubePlayerFragment)getFragmentManager()
                .findFragmentById(R.id.youtubeplayerfragment);
        youTubePlayerFragment.initialize(API_KEY, this);

        textVideoLog = (TextView)findViewById(R.id.videolog);

        btnViewFullScreen = (Button)findViewById(R.id.btnviewfullscreen);
        btnViewFullScreen.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View arg0) {
                youTubePlayer.setFullscreen(true);
            }});
    }

    @Override
    public void onInitializationFailure(Provider provider,
            YouTubeInitializationResult result) {

        if (result.isUserRecoverableError()) {
            result.getErrorDialog(this, RQS_ErrorDialog).show();    
        } else {
            Toast.makeText(this, 
                    "YouTubePlayer.onInitializationFailure(): " + result.toString(), 
                    Toast.LENGTH_LONG).show();  
        }
    }

    @Override
    public void onInitializationSuccess(Provider provider, YouTubePlayer player,
            boolean wasRestored) {

        youTubePlayer = player;

        Toast.makeText(getApplicationContext(), 
                "YouTubePlayer.onInitializationSuccess()", 
                Toast.LENGTH_LONG).show();

        if (!wasRestored) {
            //player.cueVideo(VIDEO_ID);
            player.cuePlaylist(PlayList_ID);
        }
    }
}
GSerg
  • 76,472
  • 17
  • 159
  • 346

1 Answers1

0

The playlist id, are the characters after "PL".

You can use recyclerView for the list. I have done this using Youtube api rest calls. You will need to get a browser key from the google developer console. I've explained this in my answer here:

https://stackoverflow.com/a/41201084/3689744

Community
  • 1
  • 1
cmcoffee91
  • 141
  • 3
  • 8