Created
June 30, 2015 07:14
-
-
Save vajrasar/664785ad9e2385ba65d9 to your computer and use it in GitHub Desktop.
Using Youtube iFrame API for playlist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- topplayer is the div id we'll be referencing in JS to make an iframe here --> | |
| <div id="topplayer"></div> | |
| <script> | |
| jQuery( document ).ready(function( $ ) { | |
| var tag = document.createElement( 'script' ); | |
| tag.src = "https://www.youtube.com/iframe_api"; | |
| var firstScriptTag = document.getElementsByTagName( 'script' )[0]; | |
| firstScriptTag.parentNode.insertBefore( tag, firstScriptTag ); | |
| }); | |
| function onYouTubeIframeAPIReady() { | |
| //topplayer object that will be used throughout. | |
| //I'll suggest that you don't use the object name as player as the same name is used default by youtube and may conflict | |
| topplayer = new YT.Player('topplayer', { | |
| height: '315', //height of video | |
| width: '560', //width of the video | |
| events: { | |
| 'onReady': onTopPlayerReady, | |
| } | |
| }); | |
| } | |
| function onTopPlayerReady(event) { | |
| event.target. loadPlaylist({ | |
| listType:'playlist', | |
| list: ' #Your Playlist Id# ', //insert your playlist ID | |
| index: 0, | |
| }); | |
| event.target.playVideo(); //to run video as soon as player is ready | |
| topplayer.mute(); //to mute video once it starts running | |
| } | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment