1
0
mirror of https://github.com/videojs/video.js.git synced 2025-04-21 12:17:11 +02:00
video.js/src/js/core.js

105 lines
2.6 KiB
JavaScript
Raw Normal View History

/**
2013-01-12 22:23:22 -08:00
* @fileoverview Main function src.
*/
2013-01-12 22:23:22 -08:00
goog.provide('vjs');
goog.provide('videojs');
// HTML5 Shiv. Must be in <head> to support older browsers.
document.createElement('video');document.createElement('audio');
/**
* Doubles as the main function for users to create a player instance and also
* the main library object.
*
* @param {String|Element} id Video element or video element ID
* @param {Object=} options Optional options object for config/settings
* @param {Function=} ready Optional ready callback
* @return {vjs.Player} A player instance
*/
vjs = function(id, options, ready){
2011-11-30 11:53:08 -08:00
var tag; // Element of ID
// Allow for element or ID to be passed in
// String ID
if (typeof id === 'string') {
// Adjust for jQuery ID syntax
if (id.indexOf('#') === 0) {
id = id.slice(1);
}
// If a player instance has already been created for this ID return it.
if (vjs.players[id]) {
return vjs.players[id];
// Otherwise get element for ID
} else {
tag = vjs.el(id);
}
// ID is a media element
} else {
tag = id;
}
// Check for a useable element
if (!tag || !tag.nodeName) { // re: nodeName, could be a box div also
throw new TypeError('The element or ID supplied is not valid. (videojs)'); // Returns
}
// Element may have a player attr referring to an already created player instance.
// If not, set up a new player and return the instance.
return tag['player'] || new vjs.Player(tag, options, ready);
};
// Extended name, also available externally, window.videojs
var videojs = vjs;
// CDN Version. Used to target right flash swf.
var CDN_VERSION = 'GENERATED_CDN_VSN';
/**
* Global Player instance options
* @type {Object}
*/
// var vjs = videojs;
vjs.options = {
// Default order of fallback technology
'techOrder': ['html5','flash'],
// techOrder: ['flash','html5'],
'html5': {},
'flash': { swf: 'http://vjs.zencdn.net/c/video-js.swf' },
// Default of web browser is 300x150. Should rely on source width/height.
'width': 300,
'height': 150,
2012-04-06 16:42:09 -07:00
// defaultVolume: 0.85,
'defaultVolume': 0.00, // The freakin seaguls are driving me crazy!
// Included control sets
'children': {
'mediaLoader': {},
'posterImage': {},
'textTrackDisplay': {},
'loadingSpinner': {},
'bigPlayButton': {},
'controlBar': {}
2012-01-27 15:04:25 -08:00
}
};
/**
* Global player list
* @type {Object}
*/
vjs.players = {};
// Set CDN Version of swf
if (CDN_VERSION != 'GENERATED_CDN_VSN') {
videojs.options['flash']['swf'] = 'http://vjs.zencdn.net/'+CDN_VERSION+'/video-js.swf';
}