{"id":22496,"date":"2016-06-05T03:01:54","date_gmt":"2016-06-04T17:01:54","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=22496"},"modified":"2016-06-05T10:13:11","modified_gmt":"2016-06-05T00:13:11","slug":"youtube-api-video-synchronizing-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/youtube-api-video-synchronizing-tutorial\/","title":{"rendered":"YouTube API Video Synchronizing Tutorial"},"content":{"rendered":"<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","protected":false},"excerpt":{"rendered":"<p>YouTube is a very well known, and the most popular video watching website on the &#8220;net&#8221;, owned by Google, and yesterday we started on a quest to do some work with the great YouTube API for Iframe embedded videos when &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/youtube-api-video-synchronizing-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,1896,212,452,513,576,652,997,1895,1670,1319,1345,1369,1493],"class_list":["post-22496","post","type-post","status-publish","format-standard","hentry","category-elearning","category-software","category-tutorials","tag-api","tag-binge","tag-client","tag-form","tag-google","tag-html","tag-javascript","tag-programming","tag-sequence","tag-synchronize","tag-tutorial","tag-url","tag-video","tag-youtube"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/22496"}],"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=22496"}],"version-history":[{"count":9,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/22496\/revisions"}],"predecessor-version":[{"id":22509,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/22496\/revisions\/22509"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=22496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=22496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=22496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}