{"id":22543,"date":"2016-06-07T03:01:44","date_gmt":"2016-06-06T17:01:44","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=22543"},"modified":"2016-06-06T20:41:57","modified_gmt":"2016-06-06T10:41:57","slug":"youtube-api-video-playlist-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/youtube-api-video-playlist-tutorial\/","title":{"rendered":"YouTube API Video Playlist Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/stop_start_youtube.html\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"YouTube API Video Playlist Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/youtube_api_playlist.jpg\" title=\"YouTube API Video Playlist Tutorial\"  style=\"float:left;\"  \/><\/a><p class=\"wp-caption-text\">YouTube API Video Playlist Tutorial<\/p><\/div>\n<p><a target=_blank title='Playlist information from Wikipedia ... thanks' href='https:\/\/en.wikipedia.org\/wiki\/Playlist'>Playlists<\/a> are the topic we hone in on today with the continuation of our <a target=_blank title='YouTube' href='http:\/\/youtube.com'>YouTube<\/a> <a target=_blank title='YouTube API for Iframe embedded videos' href='https:\/\/developers.google.com\/youtube\/iframe_api_reference'>API for Iframe embedded videos<\/a> &#8220;knowledge quest&#8221; today, building on yesterday&#8217;s <a title='YouTube API Start and Stop Resizing Tutorial' href='#yasascrt'>YouTube API Start and Stop Resizing Tutorial<\/a> as shown below.<\/p>\n<p>Perhaps your first exposure to a &#8220;playlist&#8221; was with the <a target=_blank title='iTunes information from Apple' href='http:\/\/www.apple.com\/au\/itunes\/'>iTunes<\/a> playlists, as receptacles for your favourite music in the form of a song list?  But &#8220;playlist&#8221; has morphed into so much more than with those early &#8220;heady&#8221; days of the <a target=_blank title='iPod information from Apple' href='http:\/\/www.apple.com\/au\/ipod\/'>iPod<\/a> we talked about with the <a target=_blank title='Kinesthetic iPod Learning Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/kinesthetic-ipod-learning-primer-tutorial\/'>Kinesthetic iPod Learning Primer Tutorial<\/a>, and we think of it today in terms of YouTube playlists of videos.  Think playlist, <a target=_blank title='Think Think Game Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/think-think-game-primer-tutorial\/'>think<\/a> media.<\/p>\n<p>The fact is, to us, looking at YouTube, there are two main sources for the concept of &#8220;receptacle&#8221; or &#8220;container&#8221; or &#8220;collection&#8221; of videos, that being &#8230;<\/p>\n<ol>\n<li>a <a target=_blank title='YouTube playlist' href='https:\/\/support.google.com\/youtube\/answer\/57792?hl=en'>playlist<\/a> &#8230; which can be created by anyone, as used by me to create the <a target=_blank title='Nala and Luna playlist' href='https:\/\/www.youtube.com\/watch?v=Ei_VUl8qdRU&#038;list=PLjsR7WjAKSPU-6URvzZ552o5cvQ2p2GYE'>Nala and Luna<\/a> &#8220;playlist&#8221;<\/li>\n<li>a <a target=_blank title='YouTube channel information' href='https:\/\/support.google.com\/youtube\/answer\/1646861?hl=en'>channel<\/a> &#8230; which is a concept you use to upload content to YouTube, and you register with YouTube to create &#8230; here is an <a target=_blank title='YouTube channel for RJM Programming' href='http:\/\/www.youtube.com\/rmetcalfeify'>RJM Programming one (channel)<\/a><\/li>\n<\/ol>\n<p>As you might expect from the explanation above, you need to sign up for a Google YouTube API <a target=_blank title='YouTube API Developer Key' href='https:\/\/developers.google.com\/youtube\/v3\/getting-started#intro'>Developer Key<\/a> to glean information about a YouTube &#8220;channel&#8221; of interest, but &#8220;playlists&#8221; are that little bit more public, and you can point at a YouTube &#8220;playlist&#8221; of interest via a URL like &#8230;<\/p>\n<p><code><br \/>\n&lt;a target=_blank title='Google Developers playlist' href='https:\/\/www.youtube.com\/watch?v=URuOw1Pi58Y&list=LLtVd0c0tGXuTSbU5d8cSBUg'&gt;<a target=_blank title='Google Developers playlist' href='https:\/\/www.youtube.com\/watch?v=URuOw1Pi58Y&#038;list=LLtVd0c0tGXuTSbU5d8cSBUg'>https:\/\/www.youtube.com\/watch?v=URuOw1Pi58Y&list=LLtVd0c0tGXuTSbU5d8cSBUg<\/a>&lt;\/a&gt;<br \/>\n<\/code><\/p>\n<p> &#8230; and so, with that in mind, we don&#8217;t try to reinvent wheels here with our new functionality of &#8220;playlist&#8221; inclusion today, but simply access one of those URLs like above via an API call like &#8230;<\/p>\n<p><code><br \/>\nvar yturlis=player.<a target=_blank title='YouTube API Retriving video information' href='https:\/\/developers.google.com\/youtube\/iframe_api_reference#Retrieving_video_information'>getVideoUrl<\/a>();<br \/>\n<\/code><\/p>\n<p> &#8230; and let the brilliance of the YouTube API add all this great &#8220;linked (video) list&#8221; functionality (you can see working in today&#8217;s <a target=_blank title='Click picture' href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/youtube_api_playlist.jpg\">tutorial picture<\/a>) to our (still only) HTML and Javascript web application you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/stop_start_youtube.html---GETME\" title='stop_start_youtube.html'>stop_start_youtube.html<\/a>, changed from yesterday in <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/stop_start_youtube.html---GETME\" title='stop_start_youtube.html'>this way<\/a> with its <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/stop_start_youtube.html\" title='Click picture'>live run<\/a> link for you to try this &#8220;playlist&#8221; functionality out for yourself.<\/p>\n<hr>\n<p id='yasascrt'>Previous relevant <a target=_blank title='YouTube API Start and Stop Resizing Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/youtube-api-start-and-stop-resizing-tutorial\/'>YouTube API Start and Stop Resizing Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/stop_start_youtube.htm\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"YouTube API Video Resizing Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/youtube_api_more.jpg\" title=\"YouTube API Video Resizing Tutorial\"  style=\"float:left;\"  \/><\/a><p class=\"wp-caption-text\">YouTube API Video Resizing Tutorial<\/p><\/div>\n<p>We continue with our <a target=_blank title='YouTube' href='http:\/\/youtube.com'>YouTube<\/a> <a target=_blank title='YouTube API for Iframe embedded videos' href='https:\/\/developers.google.com\/youtube\/iframe_api_reference'>API for Iframe embedded videos<\/a> today building on yesterday&#8217;s <a title='YouTube API Start and Stop Synchronizing Tutorial' href='#yasascst'>YouTube API Start and Stop Synchronizing Tutorial<\/a> as shown below.<\/p>\n<p>The matters we&#8217;d like to direct your attention to today are &#8230;<\/p>\n<ul>\n<li>width and height of YouTube embedded Iframe player<\/li>\n<li>audio volume<\/li>\n<li>video playback rate<\/li>\n<li>video playback quality<\/li>\n<\/ul>\n<p> &#8230; respectively involving API reference to &#8230;<\/p>\n<ul>\n<li><a target=_blank href='https:\/\/developers.google.com\/youtube\/iframe_api_reference#Loading_a_Video_Player'>width and height of YouTube embedded Iframe player<\/a> are parameters for the &#8220;Player&#8221; constructor, and we don&#8217;t use it, but you can <a target=_blank href='https:\/\/developers.google.com\/youtube\/iframe_api_reference#Playback_controls'>dynamically change width and height<\/a> via methods are discussed under &#8220;Setting the player size&#8221;<\/li>\n<li><a target=_blank href='https:\/\/developers.google.com\/youtube\/iframe_api_reference#Playback_controls'>audio volume<\/a> methods are discussed under &#8220;Changing the player volume&#8221;<\/li>\n<li><a target=_blank href='https:\/\/developers.google.com\/youtube\/iframe_api_reference#Playback_controls'>video playback rate<\/a> methods are discussed under &#8220;Setting the playback rate&#8221;<\/li>\n<li><a target=_blank href='https:\/\/developers.google.com\/youtube\/iframe_api_reference#Playback_quality'>video playback quality<\/a> methods are discussed under &#8220;Playback quality&#8221;<\/li>\n<\/ul>\n<p>Here&#8217;s the updated HTML and Javascript code you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/stop_start_youtube.html--GETME\" title='stop_start_youtube.html'>stop_start_youtube.htm<\/a>, changed from yesterday in <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/stop_start_youtube.html--GETME\" title='stop_start_youtube.html'>this way<\/a> with its <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/stop_start_youtube.htm\" title='Click picture'>live run<\/a> link for you to try these new ideas yourself.<\/p>\n<hr>\n<p id='yasascst'>Previous relevant <a target=_blank title='YouTube API Start and Stop Synchronizing Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/youtube-api-start-and-stop-synchronizing-tutorial\/'>YouTube API Start and Stop Synchronizing Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/stop_start_youtube.htm\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"YouTube API Video Synchronizing Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/youtube_synchronizing.jpg\" title=\"YouTube API Video Synchronizing Tutorial\"  style=\"float:left;\"  \/><\/a><p class=\"wp-caption-text\">YouTube API Video Synchronizing Tutorial<\/p><\/div>\n<p><a target=_blank title='YouTube' href='http:\/\/youtube.com'>YouTube<\/a> is a very well known, and the most popular video watching website on the &#8220;net&#8221;, owned by <a target=_blank title='Google' gref='http:\/\/www.google.com'>Google<\/a>, and yesterday we started on a quest to do some work with the great <a target=_blank title='YouTube API for Iframe embedded videos' href='https:\/\/developers.google.com\/youtube\/iframe_api_reference'>YouTube API for Iframe embedded videos<\/a> when we presented <a title='YouTube API Start and Stop Primer Tutorial' href='#yasaspt'>YouTube API Start and Stop Primer Tutorial<\/a> as shown below.<\/p>\n<p>We are not alone on this quest, we are sure, and today we use the API to sequence YouTube videos by adding to yesterday&#8217;s functionality with &#8230;<\/p>\n<ol>\n<li>use of an HTML <a target=_blank title='Javascript DOM document.write method information from wschools' href='http:\/\/www.w3schools.com\/html\/html_forms.asp'>form<\/a> element (<i>method=GET<\/i> <i>action=.\/stop_start_youtube.htm<\/i> <i>target=_self<\/i>) to collect follow up YouTube video ids the user wants to play<\/li>\n<li>catering for the user pausing the video, a practicality that could help give the user time to enter large numbers of follow up video &#8230; <a target=_blank title='Nala and Luna' href='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/stop_start_youtube.htm?vid=kMGJ0VyUmvI&#038;playtime=-1000&#038;this=&#038;next=kMGJ0VyUmvI&#038;next2=k8015YUEeC0&#038;next3=cGdz3GNhEQ4&#038;next4=Ei_VUl8qdRU'><i>binge<\/i><\/a> anyone?!<\/li>\n<\/ol>\n<p>The <i>method=GET<\/i> is fine because &#8230;<\/p>\n<ol>\n<li>YouTube video ids are quite short and so many can be stored in a URL without overshooting the web server length limits here &#8230; and that means &#8230;<\/li>\n<li><i>method=GET<\/i> ensures all information is contained in <i>document.URL<\/i> and entirely processed by Javascript client methodologies without the <i>method=POST<\/i> complications of involving a serverside program like PHP in this web application&#8217;s architecture<\/li>\n<\/ol>\n<p>The <i>action=.\/stop_start_youtube.htm<\/i> <i>target=_self<\/i> combination means that the change of video becomes pretty seamless, into the same original webpage of interest, using the same original HTML and Javascript codebase of interest.<\/p>\n<p>And so the mechanism for making use of this optional video synchronizing, or sequencing, functionality is to answer the video duration question with a negative number reflecting the total number of videos to play, so, again, nothing radical has changed with the look of the web application as it starts as yesterday&#8217;s functionality is still pushed as the default functionality ideas of use.<\/p>\n<p>Here&#8217;s the HTML and Javascript code you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/stop_start_youtube.html-GETME\" title='stop_start_youtube.html'>stop_start_youtube.htm<\/a>, changed from yesterday in <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/stop_start_youtube.html-GETME\" title='stop_start_youtube.html'>this way<\/a> with its <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/stop_start_youtube.htm\" title='Click picture'>live run<\/a> link for you to try this out yourself.<\/p>\n<hr>\n<p id='yasaspt'>Previous relevant <a target=_blank title='YouTube API Start and Stop Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/youtube-api-start-and-stop-primer-tutorial\/'>YouTube API Start and Stop Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/stop_start_youtube.html\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"YouTube API Stop and Start Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/youtube_start_stop.jpg\" title=\"YouTube API Start and Stop Primer Tutorial\"  style=\"float:left;\"  \/><\/a><p class=\"wp-caption-text\">YouTube API Start and Stop Primer Tutorial<\/p><\/div>\n<p><a target=_blank title='YouTube' href='http:\/\/youtube.com'>YouTube<\/a> is a very well known, and the most popular video watching website on the &#8220;net&#8221;.<\/p>\n<p>It is no surprise that programmers and developers everywhere are interested in interfacing to it.  We interface to it today, just purely with client side HTML and Javascript and the wonderful <a target=_blank title='YouTube API for Iframe embedded videos' href='https:\/\/developers.google.com\/youtube\/iframe_api_reference'>YouTube API for Iframe embedded videos<\/a> reference website, the information for which we got directed to via this <a target=_blank title='Useful link' href='http:\/\/stackoverflow.com\/questions\/6970013\/getting-current-youtube-video-time'>useful link<\/a> &#8230; so thanks, everybody.<\/p>\n<p>Using the YouTube API means you&#8217;ve got access to information, such as &#8230;<\/p>\n<ul>\n<li>the total length of the video clip<\/i>\n<li>the accumulated length you have watched<\/li>\n<\/ul>\n<p> &#8230; without which it is hard to do what we want to do today.  And that is simply to ask you for &#8230;<\/p>\n<ol>\n<li>YouTube video identifier<\/li>\n<li>how many seconds do you want to use to start and stop your way through the viewing &#8230; -1 here let&#8217;s you view the whole video in one session<\/li>\n<\/ol>\n<p>This exercise was helped enormously by the great example code at the <a target=_blank title='YouTube API for Iframe embedded videos' href='https:\/\/developers.google.com\/youtube\/iframe_api_reference'>YouTube API for Iframe embedded videos<\/a> reference website.<\/p>\n<p>Here&#8217;s the HTML and Javascript code you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/stop_start_youtube.html_GETME\" title='stop_start_youtube.html'>stop_start_youtube.html<\/a> with its <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/stop_start_youtube.html\" title='Click picture'>live run<\/a> link, as well.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d22484' onclick='var dv=document.getElementById(\"d22484\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/api\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d22484' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d22496' onclick='var dv=document.getElementById(\"d22496\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/form\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d22496' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d22510' onclick='var dv=document.getElementById(\"d22510\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/video\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d22510' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d22543' onclick='var dv=document.getElementById(\"d22543\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/playlist\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d22543' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Playlists are the topic we hone in on today with the continuation of our YouTube API for Iframe embedded videos &#8220;knowledge quest&#8221; today, building on yesterday&#8217;s YouTube API Start and Stop Resizing Tutorial as shown below. Perhaps your first exposure &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/youtube-api-video-playlist-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,33,37],"tags":[88,113,1896,212,452,513,576,652,1898,997,1897,1059,1895,1670,1319,1345,1369,1391,1493],"class_list":["post-22543","post","type-post","status-publish","format-standard","hentry","category-elearning","category-software","category-tutorials","tag-api","tag-audio","tag-binge","tag-client","tag-form","tag-google","tag-html","tag-javascript","tag-playlist","tag-programming","tag-quality","tag-resize","tag-sequence","tag-synchronize","tag-tutorial","tag-url","tag-video","tag-volume","tag-youtube"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/22543"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=22543"}],"version-history":[{"count":4,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/22543\/revisions"}],"predecessor-version":[{"id":22547,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/22543\/revisions\/22547"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=22543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=22543"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=22543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}