![]() Capt. Horatio T.P. Webb |
Version 1 -- 3/20/2016 |
www.youtube.com contains the great collection of video on the internet. It usage rates trounce any other video source site. It is common to the entire world of Internet users and as much a part the typical users Google experience as their search engine.
The central technology of the site is the flash player which is invoked by the user when a video is requested from youtube.com. This Adobe product had been around for years and is a standard for video display. Conversion from various media to the flash file format (called *.swf files) requires the use of various Adobe products to get the media into the correct video format for the flash player. youtube.com has done this task the user and the only thing to user need to do is invoke that flash player and download the *.swf file from youtube.com.
It has been a standard policy at youtube.com to provide for each video in their inventory a small snippet of code that allows anyone to "embed" a youtube video on to any web page. To find this code snippet. Load any youtube video into your browser and below the video you will see an arrow followed by the word "SHARE". If you click the "SHARE" another menu appears with a second link that says "EMBED". Click this link and in a textbox the one line the HTML code appears -- such as this:
This demonstration will NOT work in a mobile environment! On both IPhone and Android
It is will only work from a desktop
This webpage is designed to allow a user to choose from a music list and then start playing the chosen musical sellection. However, this requires the code to utilize and "autostart" which has been disabled by the mobile device manufacturers. Their rational is:
Autoplay: Not supported on iPhone or Android; supported on all desktop browsers, iPad, Firefox and Opera for Android.
or
In Safari on iOS (for all devices, including iPad), where the user may be on a cellular network and be charged per data unit, preload and autoplay are disabled. No data is loaded until the user initiates it.
or
In Safari on iOS (for all devices, including iPad), where the user may be on a cellular network and be charged per data unit, preload and autoplay are disabled. No data is loaded until the user initiates it. This means the JavaScript play() and load() methods are also inactive until the user initiates playback, unless the play() or load() method is triggered by user action. In other words, a user-initiated Play button works, but an onLoad="play()" event does not.
The HTML says to place an iframe (a container with some HTML inside it which can appear anywhere on a webpage). This iframe:
If you know the video's identifier, you can do more things than take it as youtube.com gave it to you.
What follows is a general discussion of how to customize a flash player.
The "swfobject" (the player for the *.swf files) is created by:
swfobject.embedSWF(swftoplay, id, width, height, version, expressInstallSwfurl, flashvars, params, attributes)
Of the following attributes, the first 5 are ALL REQUIRED:
we will not use flashvars in this example but we will add this empty definition before the swfobject.embedSWF as we have to pass something as the values of the flashvars (in this case nothing)
var flashvars = {};
The params list of options is:
As the second optional part of the swfobject.embedSWF we can specify the params like this:
var params = {
parameter_name_1 : "value" ,
parameter_name_2 : "value" ,
parameter_name_3 : "value" ,
.
.
.
};
For example:
var params = {
autostart: "true" ,
menu: "false" ,
loop: "true" ,
allowscriptaccess: "always",
};
We seldom use the attribute and rely on the params for most customization
Here is a complete javascript example:
var flashvars = {};
var params = {
autostart: "true" ,
menu: "false" ,
loop: "true" ,
allowscriptaccess: "always" ,
};
var attributes = {};
swfobject.embedSWF(
"http://URL/path/swf filename.swf",
"fout",
"360", "270",
"9.0.0","expressInstall.swf",
flashvars, params, attributes);
Then on the HTML page would be the DIV with the id (the second parameter of the swfobject.embedSWF -- in this case the name coden was "fout") like this:
The purpose here is to demonstrate the degree of control you have over the youtube player in a standalone environment you create yourself.
But with youtube, Google recommends (insists) you use their player definition that comes with the "embed" tag demonstrated above.
See what Google says here about the way it load the HTML iframe from the recommended "embed" that comes with each youtube video:
https://developers.google.com/youtube/iframe_api_reference
Google provides a script to use in your HTML pages. It runs in-line (i.e., as the page is loaded and parsed the code is executed as encountered). Here is their recommended use of the embeded youtube video:
The code/HTML above:
This is OK for a single embed for a single youtube video. But we have grander aspirations. What we will do is make a playlist (i.e., a lot of videos that our user can pick from) and annotate each video (i.e, provide some additional text to show along side the video). We will you my top 30 Bob Dylan songs as our video playlist and show the lyrics as the songs play (a necessary aid as the lyrics are complicated and are not sometimes easy to pick out over the music and Dylan's often emotional verbal expression)
The live version of the page is here:
http://www.bauer.uh.edu/parks/utest2.htm
Go to the page and watch and listen. Click on any of the 30 songs in the blue list below the player. There are also a few straight .mp3 audio files that did not come from youtube. We will deal with these audios differently.
Here is complete annotated code (shortened to make it easier to understand)