Easy Tutorial step by step with free source code: play videos from YouTube playlist using YouTube Android Player API in Android Studio version 1.5.1. Learn how to download and import YouTube Android Player API and how to Register your app using YouTube Android Player API and obtain API Key. Create new project with Application name: Play YouTube Playlist; Minimum SDK: API 10 – Android 2.3.3 (Gingerbread). Download YouTube Android Player API: https://developers.google.com/youtube/android/player/downloads/ Copy YouTubeAndroidPlayerApi.jar file to /libs folder in your project. Add YouTubeAndroidPlayerApi.jar library in your project (see video tutorial from below). In manifest->AndroidManifest.xml add the permission:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    <uses-permission android:name="android.permission.INTERNET" />

        <activity android:name=".MainActivity">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />

In app->res->layout->activity_main.xml add the code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

In app->java->MainActivity.java complete the code:
package com.app.toyo.playyoutubeplaylist;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayer.ErrorReason;
import com.google.android.youtube.player.YouTubePlayer.PlaybackEventListener;
import com.google.android.youtube.player.YouTubePlayer.PlayerStateChangeListener;
import com.google.android.youtube.player.YouTubePlayer.Provider;
import com.google.android.youtube.player.YouTubePlayerView;

public class MainActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener {

    public static final String API_KEY = "YOUR API KEY!!";
    public static final String PlayList_ID = "YOUR PLAYLIST ID!!";

    protected void onCreate(Bundle savedInstanceState) {

        /** Initializing YouTube Player View **/
        YouTubePlayerView youTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtube_player);
        youTubePlayerView.initialize(API_KEY, this);

    public void onInitializationFailure(Provider provider, YouTubeInitializationResult result) {
        Toast.makeText(this, "Failured to Initialize!", Toast.LENGTH_LONG).show();
    public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasRestored) {
        /** add listeners to YouTubePlayer instance **/
        /** Start buffering **/
        if (!wasRestored) {

    private PlaybackEventListener playbackEventListener = new PlaybackEventListener() {
        public void onBuffering(boolean arg0) {
        public void onPaused() {
        public void onPlaying() {
        public void onSeekTo(int arg0) {
        public void onStopped() {

    private PlayerStateChangeListener playerStateChangeListener = new PlayerStateChangeListener() {
        public void onAdStarted() {
        public void onError(ErrorReason arg0) {
        public void onLoaded(String arg0) {
        public void onLoading() {
        public void onVideoEnded() {
        public void onVideoStarted() {
Obtain your API Key from Google APIs: https://code.google.com/apis/console (e.g. AIzaSyCe6tORd9Ch4lx-9Ku5SQ476uS9OtZYsWA) – see video tutorial from below. Get your Playlist ID from YouTube (e.g. PL1LAkZ-M7pNKwicHAlI3HGQMH0jofeXmd) – see video tutorial from below. Run app in mobile device and use next and previous buttons to watch videos from youtube playlist in format portrait, landscape and full screen. See the result of app in screenshot from mobile device: play videos from YouTube playlist using YouTube Android Player APIThis doesn’t work on Emulator. It work only on mobile device! Emulator can’t play YouTube videos, because YouTube have different formats (avi, mp4, mov, wmv etc) than emulator which supports only 3gp videos. Watch the VIDEO TUTORIAL How to Play Videos PLAYLIST YouTube using YouTube Android Player API in Android Studio: See here an video example recorded from tablet of how this app works. App has next and prev video button, portrait and landscape orientation, quality video options and fullscreen. Download free PlayList-YouTube.apk application from here and install it on your mobile device to see how it works. Please subscribe here to our youtube channel. Thank you! Check next tutorials to learn all about Android. For further questions leave a message.  


You can follow any responses to this entry through the RSS 2.0 feed.

Thanks , that help me , but how to show the playlist in android studio

thank you so much its working perfectly..
but how to display videos in list so that user can select videos from playlist. please help me

Thanks , but how to show the playlist all video and show them oncliclick particular video open in android studio

Como puedo hacer de que me coja todas las url de mi base de datos y las muestre con la api

Leave a Reply

Your email address will not be published. Required fields are marked *

Blue Captcha Image Refresh