HTML5 goodness! Last year, YouTube introduced an HTML5 based implementation
of their embedded player. With the proliferation of mobile devices, the increasing popularity of Apple's iPad,
and Apple's stringent requirements around the use of Flash, access to control the HTML5 player has been in great demand. This implementation was first provided for simple embeds and offered as a trial-service on YouTube itself.
Just last month, however, YouTube announced developer access to this HTML5 version of the player. The API was of course created in line with what they had set out for their original JavaScript Player API, which meant that the general pattern and structure that the TubePlayer plugin was maintained; the only difference was around the instantiation of the player itself.
So, what's so great about the YouTube HTML5 player, anyway? Well, basically iPad/iPhone support, enhancemened performance, optimized resource usage, conforming to standards and end user experience. Check this great article on the advantages of the standards based video implementation in HTML5. While I am excited and enthused about providing a plugin that provides iOS (iPad/iPhone) support, i'm disappointed to have to tell you that with the player still in labs mode the player still has some kinks. In addition to the occasional bug, mobile development adds additional complexities. An example is with the potential fees involved in streaming video, Apple dictates that the user must initiate playback, essentially removing possibilities for auto-playing videos in a playlists. For more information, see this forum thread.
The updated TubePlayer plugin takes advantage of HTML5 where possible. A new attribute iframed can be set to true or false depending on whether the iframe player should be prioritized. SWFObject is not strictly a requirement anymore, however TubePlayer has been created such that if the browser does not support HTML5 video, the flash player will be used instead. Anyone upgrading from previous versions of the TubePlayer plugin, all you have to do is replace your jQuery.tubeplayer.js file with the updated code. There is no need to worry about your implementation, as everything is backwards compatible.
YouTube broke 2 billion views a day just a couple of months back. I have played around with the API for two and a half years in various capacities, but I always stopped at the flash level of the chromeless player. Even though I managed to work through the AS3 implementation, I didn't want to have to go through the pain of designing an interface for a player - I really wanted to play with the API itself.
I recently took a look at the updates to the YouTube API, and I was excited to see that the embeddable player is now controllable through the JavaScript API. As a result I threw it into an example that I created showcasing my other plugin, the jQuery Radmenu plugin. I wanted to have access to the player state change (so I could tell when the player had finished playing the active video) and as a result was capable of creating a sort of 'YouTube wheel' that just continuously plays.
All of my implementations of the YouTube API have been around the creation of playlists and/or stringing specific videos outside of the standard YouTube playlist implementation. The player is the integral part since you need to have a hook when the player has ended to queue up the next video.
Basically this jQuery plugin implements the YouTube Player API pretty much to spec. I've omitted some functions but believe I have captured most of the functionality a developer will need to implement a youtube player. The kind of things that this plugin allows the developer to simply get done are --
If you have any comments, suggestions, or need/want help implementing this plugin - please feel free to email me @ ntikku@gmail.com or tweet me @ntikku . Also, if you do end up implementing this plugin, I would greatly appreciate it if you would send a link over - I'd love to see it in action!
Thanks,
Nirvana Tikku
<html>
<body>
<div id='youtube-player-container'> </div>
</body>
</html>
<script type='text/javascript' src='{your_path_to}/jQuery.tubeplayer.js'></script>
jQuery("#youtube-player-container").tubeplayer({ width: 600, // the width of the player height: 450, // the height of the player allowFullScreen: "true", // true by default, allow user to go full screen initialVideo: "DkoeNLuMbcI", // the video that is loaded into the player preferredQuality: "default",// preferred quality: default, small, medium, large, hd720 onPlay: function(id){}, // after the play method is called onPause: function(){}, // after the pause method is called onStop: function(){}, // after the player is stopped onSeek: function(time){}, // after the video has been seeked to a defined point onMute: function(){}, // after the player is muted onUnMute: function(){} // after the player is unmuted });
<a href="#" onClick='jQuery("#youtube-player-container").tubeplayer("play")'> Play video in player </a> <a href="#" onClick='jQuery("#youtube-player-container").tubeplayer("pause")'> Pause player </a> <a href="#" onClick='jQuery("#youtube-player-container").tubeplayer("stop")'> Stop player </a> <a href="#" onClick='jQuery("#youtube-player-container").tubeplayer("mute")'> Mute player </a> <a href="#" onClick='jQuery("#youtube-player-container").tubeplayer("unmute")'> Unmute player </a>
var defaults = { // Plugin init params width: 425, // the width of the player height: 355, // the height of the player allowFullScreen: "true", // true by default, allow user to go full screen initialVideo: "DkoeNLuMbcI", // the video that is loaded into the player start: 0, preferredQuality: "default",// preferred quality: default, small, medium, large, hd720 showControls: 1, // whether the player should have the controls visible, 0 or 1 showRelated: 0, // show the related videos when the player ends, 0 or 1 autoPlay: false, // whether the player should autoplay the video, 0 or 1 autoHide: true, theme: "dark", // possible options: "dark" or "light" color: "red", // possible options: "red" or "white" showinfo: false, // if you want the player to include details about the video modestbranding: true, // specify to include/exclude the YouTube watermark // the location to the swfobject import for the flash player, default to Google's CDN wmode: "transparent", // note: transparent maintains z-index, but disables GPU acceleration swfobjectURL: "http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js", loadSWFObject: true, // if you include swfobject, set to false // HTML5 specific attrs iframed: true, // iframed can be: true, false; if true, but not supported, degrades to flash // Player Trigger Specific Functionality onPlay: function(id){}, // after the play method is called onPause: function(){}, // after the pause method is called onStop: function(){}, // after the player is stopped onSeek: function(time){}, // after the video has been seeked to a defined point onMute: function(){}, // after the player is muted onUnMute: function(){}, // after the player is unmuted // Player State Change Specific Functionality onPlayerUnstarted: function(){}, // when the player returns a state of unstarted onPlayerEnded: function(){}, // when the player returns a state of ended onPlayerPlaying: function(){}, //when the player returns a state of playing onPlayerPaused: function(){}, // when the player returns a state of paused onPlayerBuffering: function(){}, // when the player returns a state of buffering onPlayerCued: function(){}, // when the player returns a state of cued onQualityChange: function(quality){}, // a function callback for when the quality of a video is determined // Error State Specific Functionality onErrorNotFound: function(){}, // if a video cant be found onErrorNotEmbeddable: function(){}, // if a video isnt embeddable onErrorInvalidParameter: function(){} // if we've got an invalid param });
jQuery("#youtube-player-container")
.tubeplayer("cue", "videoId");
jQuery("#youtube-player-container")or
.tubeplayer("play");
jQuery("#youtube-player-container")or
.tubeplayer("play", "DkoeNLuMbcI");
jQuery("#youtube-player-container")
.tubeplayer("play", { id: "DkoeNLuMbcI", time: 20 });
jQuery("#youtube-player-container")
.tubeplayer("pause");
jQuery("#youtube-player-container")
.tubeplayer("stop");
jQuery("#youtube-player-container")
.tubeplayer("seek", 100);
jQuery("#youtube-player-container")
.tubeplayer("mute");
jQuery("#youtube-player-container")
.tubeplayer("unmute");
jQuery("#youtube-player-container")
.tubeplayer("isMuted");
jQuery("#youtube-player-container")or
.tubeplayer("volume");
jQuery("#youtube-player-container")
.tubeplayer("volume", 25);
jQuery("#youtube-player-container")or
.tubeplayer("quality");
jQuery("#youtube-player-container")
.tubeplayer("quality", "medium");
jQuery("#youtube-player-container")
.tubeplayer("data");
jQuery("#youtube-player-container")
.tubeplayer("player");
jQuery("#youtube-player-container")
.tubeplayer("size", { width: 300, height: 200 });
jQuery("#youtube-player-container")
.tubeplayer("destroy");
$.tubeplayer.defaults.afterReady
= function($player){}
$.tubeplayer.getPlayers()
v1.0.3 - Aug 14th, 2011
v1.0.2 - Aug 3rd, 2011
v1.0.1 - May 14th, 2011
v1.0.0 - Feb 13th, 2011
v0.9.4 - Sept 5th, 2010
v0.9.3 - Aug 20, 2010
v0.9.2 - Aug 10, 2010
v0.9.1 - July 30, 2010
v0.9.0 - July 24, 2010
jQuery 1.3.2+
SWFObject. As per YouTube's suggestion, the best flash embedding plugin is the SWFObject. As a result this plugin is dependent on it. There are several reasons for this, but simply put it guarantees cross browser support, particularly in Internet Explorer. Note, with the updated support utilizing the iframe/HTML5 solution, the swfobject import is not used. However, in order to degrade the TubePlayer plugin, where HTML5 is not supported, the flash based player will require swfobject.
Nirvana Tikku, Tikku.com © 2010-2011