Merge branch 'dev' into feature-youtube

This commit is contained in:
Kasper Moskwiak 2015-12-19 21:34:33 +01:00
commit 40ea2182fb

View file

@ -15,13 +15,13 @@
} }
(function(window, videojs) { (function(window, videojs) {
var defaults = {}, var defaults = {},
videoJsResolutionSwitcher, videoJsResolutionSwitcher,
currentResolution = {}, // stores current resolution currentResolution = {}, // stores current resolution
menuItemsHolder = {}; // stores menuItems menuItemsHolder = {}; // stores menuItems
function setSourcesSanitized(player, sources, label, customSourcePicker) { function setSourcesSanitized(player, sources, label, customSourcePicker) {
currentResolution = { currentResolution = {
label: label, label: label,
@ -34,7 +34,7 @@
return {src: src.src, type: src.type, res: src.res}; return {src: src.src, type: src.type, res: src.res};
})); }));
} }
/* /*
* Resolution menu item * Resolution menu item
*/ */
@ -71,6 +71,10 @@
if(!isPaused){ if(!isPaused){
this.player_.bigPlayButton.hide(); this.player_.bigPlayButton.hide();
} }
if(typeof customSourcePicker !== 'function' &&
typeof this.options_.customSourcePicker === 'function'){
customSourcePicker = this.options_.customSourcePicker;
}
// Change player source and wait for loadeddata event, then play video // Change player source and wait for loadeddata event, then play video
// loadedmetadata doesn't work right now for flash. // loadedmetadata doesn't work right now for flash.
// Probably because of https://github.com/videojs/video-js-swf/issues/124 // Probably because of https://github.com/videojs/video-js-swf/issues/124
@ -90,8 +94,8 @@
}); });
} }
}); });
/* /*
* Resolution menu button * Resolution menu button
*/ */
@ -102,9 +106,9 @@
this.label = label; this.label = label;
this.label.innerHTML = options.initialySelectedLabel; this.label.innerHTML = options.initialySelectedLabel;
// Sets this.player_, this.options_ and initializes the component // Sets this.player_, this.options_ and initializes the component
MenuButton.call(this, player, options); MenuButton.call(this, player, options, settings);
this.controlText('Quality'); this.controlText('Quality');
if(settings.dynamicLabel){ if(settings.dynamicLabel){
this.el().appendChild(label); this.el().appendChild(label);
}else{ }else{
@ -121,7 +125,7 @@
item.selected(item === clickedItem); item.selected(item === clickedItem);
}); });
}; };
for (var key in labels) { for (var key in labels) {
if (labels.hasOwnProperty(key)) { if (labels.hasOwnProperty(key)) {
menuItems.push(new ResolutionMenuItem( menuItems.push(new ResolutionMenuItem(
@ -129,7 +133,8 @@
{ {
label: key, label: key,
src: labels[key], src: labels[key],
initialySelected: key === this.options_.initialySelectedLabel initialySelected: key === this.options_.initialySelectedLabel,
customSourcePicker: this.options_.customSourcePicker
}, },
onClickUnselectOthers, onClickUnselectOthers,
this.label)); this.label));
@ -140,7 +145,7 @@
return menuItems; return menuItems;
} }
}); });
/** /**
* Initialize the plugin. * Initialize the plugin.
* @param {object} [options] configuration for the plugin * @param {object} [options] configuration for the plugin
@ -148,10 +153,11 @@
videoJsResolutionSwitcher = function(options) { videoJsResolutionSwitcher = function(options) {
var settings = videojs.mergeOptions(defaults, options), var settings = videojs.mergeOptions(defaults, options),
player = this, player = this,
label = document.createElement('span'); label = document.createElement('span'),
groupedSrc = {};
label.classList.add('vjs-resolution-button-label'); label.classList.add('vjs-resolution-button-label');
/** /**
* Updates player sources or returns current source URL * Updates player sources or returns current source URL
* @param {Array} [src] array of sources [{src: '', type: '', label: '', res: ''}] * @param {Array} [src] array of sources [{src: '', type: '', label: '', res: ''}]
@ -167,14 +173,14 @@
} }
//Sort sources //Sort sources
src = src.sort(compareResolutions); src = src.sort(compareResolutions);
var groupedSrc = bucketSources(src); groupedSrc = bucketSources(src);
var choosen = chooseSrc(groupedSrc, src); var choosen = chooseSrc(groupedSrc, src);
var menuButton = new ResolutionMenuButton(player, { sources: groupedSrc, initialySelectedLabel: choosen.label , initialySelectedRes: choosen.res }, settings, label); var menuButton = new ResolutionMenuButton(player, { sources: groupedSrc, initialySelectedLabel: choosen.label , initialySelectedRes: choosen.res , customSourcePicker: settings.customSourcePicker}, settings, label);
menuButton.el().classList.add('vjs-resolution-button'); menuButton.el().classList.add('vjs-resolution-button');
player.controlBar.resolutionSwitcher = player.controlBar.addChild(menuButton); player.controlBar.resolutionSwitcher = player.controlBar.addChild(menuButton);
return setSourcesSanitized(player, choosen.sources, choosen.label); return setSourcesSanitized(player, choosen.sources, choosen.label);
}; };
/** /**
* Returns current resolution or sets one when label is specified * Returns current resolution or sets one when label is specified
* @param {String} [label] label name * @param {String} [label] label name
@ -188,7 +194,11 @@
} }
return player; return player;
}; };
player.getGroupedSrc = function(){
return groupedSrc;
}
/** /**
* Method used for sorting list of sources * Method used for sorting list of sources
* @param {Object} a - source object with res property * @param {Object} a - source object with res property
@ -199,7 +209,7 @@
if(!a.res || !b.res){ return 0; } if(!a.res || !b.res){ return 0; }
return (+b.res)-(+a.res); return (+b.res)-(+a.res);
} }
/** /**
* Group sources by label, resolution and type * Group sources by label, resolution and type
* @param {Array} src Array of sources * @param {Array} src Array of sources
@ -215,24 +225,24 @@
initResolutionKey(resolutions, 'label', source); initResolutionKey(resolutions, 'label', source);
initResolutionKey(resolutions, 'res', source); initResolutionKey(resolutions, 'res', source);
initResolutionKey(resolutions, 'type', source); initResolutionKey(resolutions, 'type', source);
appendSourceToKey(resolutions, 'label', source); appendSourceToKey(resolutions, 'label', source);
appendSourceToKey(resolutions, 'res', source); appendSourceToKey(resolutions, 'res', source);
appendSourceToKey(resolutions, 'type', source); appendSourceToKey(resolutions, 'type', source);
}); });
return resolutions; return resolutions;
} }
function initResolutionKey(resolutions, key, source) { function initResolutionKey(resolutions, key, source) {
if(resolutions[key][source[key]] == null) { if(resolutions[key][source[key]] == null) {
resolutions[key][source[key]] = []; resolutions[key][source[key]] = [];
} }
} }
function appendSourceToKey(resolutions, key, source) { function appendSourceToKey(resolutions, key, source) {
resolutions[key][source[key]].push(source); resolutions[key][source[key]].push(source);
} }
/** /**
* Choose src if option.default is specified * Choose src if option.default is specified
* @param {Object} groupedSrc {res: { key: [] }} * @param {Object} groupedSrc {res: { key: [] }}
@ -252,13 +262,13 @@
} else if (groupedSrc.res[selectedRes]) { } else if (groupedSrc.res[selectedRes]) {
selectedLabel = groupedSrc.res[selectedRes][0].label; selectedLabel = groupedSrc.res[selectedRes][0].label;
} }
if(selectedRes === undefined){ if(selectedRes === undefined){
return {res: selectedRes, label: selectedLabel, sources: groupedSrc.label[selectedLabel]}; return {res: selectedRes, label: selectedLabel, sources: groupedSrc.label[selectedLabel]};
} }
return {res: selectedRes, label: selectedLabel, sources: groupedSrc.res[selectedRes]}; return {res: selectedRes, label: selectedLabel, sources: groupedSrc.res[selectedRes]};
} }
// Create resolution switcher for videos form <source> tag inside <video> // Create resolution switcher for videos form <source> tag inside <video>
if(player.options_.sources.length > 1){ if(player.options_.sources.length > 1){
// Wait for player ready event // Wait for player ready event
@ -286,9 +296,9 @@
} }
}) })
} }
}; };
// register the plugin // register the plugin
videojs.plugin('videoJsResolutionSwitcher', videoJsResolutionSwitcher); videojs.plugin('videoJsResolutionSwitcher', videoJsResolutionSwitcher);
})(window, videojs); })(window, videojs);