/**
* Various tools for the HTML5 video element
*
* Meant to be used with CSS in /styles/tignish/video-player.css.
*
* This file contains Flash-detection routines adapted from SWFObject and
* originally licensed under the MIT license.
*
* See http://blog.deconcept.com/flashobject/
*
* This file can make use of the SMILE-based subtitling routines provided
* courtesy of Fabien Cazenave for INRIA under the BSD license. Those are
* stored in mozilla-video-tools-addsubtitles.js
*
*
* @copyright 2009-2011 Mozilla Corporation
* @author Michael Gauthier
*/
// create namespace
if (typeof Mozilla == 'undefined') {
var Mozilla = {};
}
// {{{ Mozilla.VideoControl
/**
* Initializes video controls on this page after the document has been loaded
*/
$(document).ready(function() {
$('.mozilla-video-control').each(function() {
Mozilla.VideoControl.controls.push(
new Mozilla.VideoControl($(this))
)
});
});
/**
* Provides a click-to-play button for HTML5 video element content
*
* If the HTML5 video element is supported, the following markup will
* automatically get the click-to-play button when the page initializes:
*
* <div class="mozilla-video-control">
* <video ... />
* </div>
*
*
* @param jQuery|String container
*/
Mozilla.VideoControl = function(container)
{
if (typeof container == 'String') {
container = $('#' + container);
}
this.container = container;
// Retrieve jQuery object and the corresponding DOM element
this.video = container.find('video:first');
this._video = this.video[0];
this.semaphore = false;
/*
* Check if HTMLMediaElement exists to filter out browsers that do not
* support the video element.
*/
if ( typeof HTMLMediaElement != 'undefined'
&& this._video instanceof HTMLMediaElement
) {
this.drawControl();
this._video._control = this;
}
}
Mozilla.VideoControl.controls = [];
Mozilla.VideoControl.prototype.drawControl = function()
{
var buttonTag = '' +
'' +
this._video.id +
'';
this.control = $(buttonTag);
// Show the click-to-play button. In the future, this may be changed
// to show the click-to-play button based on media events like the
// hiding is done.
if (this._video.paused || this._video.ended) {
this.show();
}
var that = this;
// hide click-to-play button on these events
this.video.bind('play playing seeking waiting', function(event) {
that.hide();
});
this.control.mouseover(function(event) {
if (!that.semaphore) {
that.prelight();
}
});
this.control.mouseout(function(event) {
if (!that.semaphore) {
that.unprelight();
}
});
this.control.click(function(event) {
event.preventDefault();
if (that.semaphore || !that.videoCanPlay()) {
return;
}
that.semaphore = true;
// rewind the video
if (that._video.ended) {
that._video.currentTime = 0;
}
that._video.play();
});
this.container.append(this.control);
}
Mozilla.VideoControl.prototype.videoCanPlay = function()
{
// check if we're using an older draft version of the readyState spec
var current_data = (typeof HTMLMediaElement.CAN_PLAY == 'undefined') ?
HTMLMediaElement.HAVE_CURRENT_DATA : HTMLMediaElement.CAN_PLAY;
return (this._video.readyState >= current_data);
}
Mozilla.VideoControl.prototype.show = function()
{
var that = this;
this._video.controls = false;
// FIXME : Does not work on http://mozilla.local/en-US/firefox/video/
// this.control.show();
this.control.css('display', 'block');
this.control.stop(true).fadeTo('slow', 0.7, function() {
that.semaphore = false;
});
}
Mozilla.VideoControl.prototype.hide = function()
{
var that = this;
if (this.control.is(':visible')) {
this.semaphore = true;
this.control.stop(true).fadeTo('fast', 0, function() {
$(this).hide();
that._video.controls = true;
});
}
}
Mozilla.VideoControl.prototype.prelight = function()
{
if (this.control.is(':visible')) {
this.control.stop(true).fadeTo('fast', 1);
}
}
Mozilla.VideoControl.prototype.unprelight = function()
{
if (this.control.is(':visible')) {
this.control.stop(true).fadeTo('fast', 0.7);
}
}
// }}}
// {{{ Mozilla.VideoPlayer
/**
* Popup player using HTML5 video element with flash fallback
*
* @param String id
* @param Array sources
* @param String flv_url
* @param Booelan autoplay
*/
Mozilla.VideoPlayer = function(id, sources, flv_url, autoplay, extra_content)
{
this.id = id;
this.flv_url = flv_url;
this.sources = sources;
this.opened = false;
if (arguments.length > 3) {
this.autoplay = autoplay;
} else {
this.autoplay = true;
}
if (arguments.length > 4) {
this.extra_content = extra_content;
} else {
this.extra_content = '';
}
var that = this;
$(document).ready(function() {
that.init();
});
}
Mozilla.VideoPlayer.height = 385;
Mozilla.VideoPlayer.width = 640;
Mozilla.VideoPlayer.ie6 =
($.browser.msie && parseInt($.browser.version, 10) <= 6);
Mozilla.VideoPlayer.close_text = 'Close';
Mozilla.VideoPlayer.fallback_text =
'This video requires a browser with support for open video or the '
+ 'Adobe Flash '
+ 'Player. Alternatively, you may use the video download links '
+ 'provided.';
Mozilla.VideoPlayer.prototype.init = function()
{
var that = this;
// add overlay and preview image to document
this.overlay = $('')
.hide()
.appendTo('body')
.click(function(e) { e.preventDefault(); that.close(); });
this.video_container = $('