asok Buzz
asok Buzz

Reputation: 1894

Play all videos of a playlist from yoututbe data api

I can get video id from PlaylistItems and play them using youtube player. But is there any way I can get the entire playlist to be played (one video after another like on youtube). On youtube for any playlist we have url like

https://www.youtube.com/watch?v=zqpkt80WbX0&list=RDaPevLsjcJ7c&index=6

How do we get the 'list' for any video?

Upvotes: 0

Views: 897

Answers (4)

DaveyJake
DaveyJake

Reputation: 2439

Figured this out after looking at a YouTube channel's source code. It uses the publicly accessible client-side API via your web browser. For this solution to work, you will be creating a bookmarklet.

Follow these steps...

  1. Go to any YouTube channel's homepage -- we'll use https://www.youtube.com/@DonutOperator.
  2. Create a new bookmark using your browser's bookmark manager.
  3. Paste the following snippet where you would normally add a URL and save your new bookmark -- don't forget to name it something you'll remember:
javascript:window.location="/playlist?list=UU"+ytInitialData.metadata.channelMetadataRenderer.externalId.substring(2)
  1. Click on the bookmark while viewing the current YouTube channel (i.e. @DonutOperator).
  2. It will redirect you to an auto-generated playlist of all videos for that channel in reverse chronological order by default.
  3. Click the Play all button and enjoy!

Upvotes: 0

asok Buzz
asok Buzz

Reputation: 1894

I used the following intent-metho

Intent videoint = YouTubeStandalonePlayer.createPlaylistIntent(MyActivity.this, KEY,
                                playlistID, position, 0, true, false);
startActivityForResult(videoint,STANDALONE_PLAYER_REQUEST_CODE);

Upvotes: 0

jlmcdonald
jlmcdonald

Reputation: 13667

I'm assuming you already have the Playlist ID? So if you're just trying to use an iframe embed, you can set the source of the iframe to look at the playlist, like this:

<iframe width="560" height="315" src="http://www.youtube.com/embed?listType=playlist&amp;list=RDaPevLsjcJ7c" frameborder="0" allowfullscreen></iframe>

That will use YouTube's embedded playlist player, where the top left-hand corner gives you playlist controls, the media bar has skip buttons, it autoplays to the next video, etc. IT's a different interface than what you see at the YouTube.com site, but it's still nice.

IF you're looking to have a bit more control than just an iframe, you can use the playlist capabilities of the YouTube Player API to hook into the playlist -- and then you can load a new playlist if you'd like, or track the index. Here's some sample example that illustrates such functionality (just demo code ... you'd want to adjust to fit your needs):

<html>
<head>
</head>
<body>
<iframe id="player" width="560" height="315" src="http://www.youtube.com/embed?listType=playlist&amp;list=RDaPevLsjcJ7c&enablejsapi=1&origin=http://humdev.byu.edu" frameborder="0" allowfullscreen></iframe>
<script>
 var tag = document.createElement('script');
 tag.src = "https://www.youtube.com/iframe_api";
 var firstScriptTag = document.getElementsByTagName('script')[0];
 firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

var player;
function onYouTubeIframeAPIReady() {
  player = new YT.Player('player', {
    height: '390',
    width: '640',
    events: {
      'onReady': onPlayerReady,
      'onStateChange': onPlayerStateChange
    },

  });
}

onPlayerReady = function() {
        player.loadPlaylist('PL028565C616627F50');
};

onPlayerStateChange = function(evt) {
        console.log(evt);
        if (evt.data === YT.PlayerState.PLAYING) {
                alert(player.getPlaylistIndex());
        }
};
</script>
</body>
</html>

(as an aside, one thing to note is that you can, with the 'loadPlaylist' method, pass in a regular video ID instead of a playlist id ... and it will make a playlist of the single video with the playlist player interface. Don't know when that would be useful, but it works!)

Finally, it may also be helpful to know that when using the player API, if you want to construct your own playlist dynamically you can do so and still use the embeddable playlist player; simply pass in a 'playlist' parameter with a comma-delimited list of videoIDs when constructing your player object, like this:

 function onYouTubeIframeAPIReady() {
  var player;
  player = new YT.Player('player', {
    videoId: 'M7lc1UVf-VE',
    playerVars: { 'autoplay': 1, 'playlist': 'yCjJyiqpAuU,GoSq-yZcJ-4' },
  });
}

Upvotes: 1

user3740085
user3740085

Reputation: 244

You are on a wrong way..your URL should be look like this:

String URL = "https://gdata.youtube.com/feeds/api/playlists/your_playlist_Id"; 

After this you have parse it. Its available in both json as well as xml. In Json your playlist URL will be:

https://gdata.youtube.com/feeds/api/playlists/RDaPevLsjcJ7c?v=2&alt=json

Still have any more issues..

Upvotes: 1

Related Questions