mirror of
https://github.com/kmoskwiak/videojs-resolution-switcher.git
synced 2025-10-03 17:59:42 +02:00
Merge branch 'feature-10-setResolution'
This commit is contained in:
commit
62fb58e3d4
1 changed files with 22 additions and 9 deletions
|
@ -19,7 +19,8 @@
|
||||||
|
|
||||||
var defaults = {},
|
var defaults = {},
|
||||||
videoJsResolutionSwitcher,
|
videoJsResolutionSwitcher,
|
||||||
currentResolution = {};
|
currentResolution = {}, // stores current resolution
|
||||||
|
menuItemsHolder = {}; // stores menuItems
|
||||||
|
|
||||||
function setSourcesSanitized(player, sources, label) {
|
function setSourcesSanitized(player, sources, label) {
|
||||||
currentResolution = {
|
currentResolution = {
|
||||||
|
@ -70,7 +71,7 @@
|
||||||
// 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
|
||||||
setSourcesSanitized(this.player_, this.src, this.label).one('loadeddata', function() {
|
setSourcesSanitized(this.player_, this.src, this.options_.label).one('loadeddata', function() {
|
||||||
this.player_.currentTime(currentTime);
|
this.player_.currentTime(currentTime);
|
||||||
this.player_.handleTechSeeked_();
|
this.player_.handleTechSeeked_();
|
||||||
if(!isPaused){
|
if(!isPaused){
|
||||||
|
@ -124,6 +125,8 @@
|
||||||
},
|
},
|
||||||
onClickUnselectOthers,
|
onClickUnselectOthers,
|
||||||
this.label));
|
this.label));
|
||||||
|
// Store menu item for API calls
|
||||||
|
menuItemsHolder[key] = menuItems[menuItems.length - 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return menuItems;
|
return menuItems;
|
||||||
|
@ -132,7 +135,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the plugin.
|
* Initialize the plugin.
|
||||||
* @param options (optional) {object} configuration for the plugin
|
* @param {object} [options] configuration for the plugin
|
||||||
*/
|
*/
|
||||||
videoJsResolutionSwitcher = function(options) {
|
videoJsResolutionSwitcher = function(options) {
|
||||||
var settings = videojs.mergeOptions(defaults, options),
|
var settings = videojs.mergeOptions(defaults, options),
|
||||||
|
@ -141,6 +144,11 @@
|
||||||
|
|
||||||
label.classList.add('vjs-resolution-button-label');
|
label.classList.add('vjs-resolution-button-label');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates player sources or returns current source URL
|
||||||
|
* @param {Array} [src] array of sources [{src: '', type: '', label: '', res: ''}]
|
||||||
|
* @returns {Object|String|Array} videojs player object if used as setter or current source URL, object, or array of sources
|
||||||
|
*/
|
||||||
player.updateSrc = function(src){
|
player.updateSrc = function(src){
|
||||||
//Return current src if src is not given
|
//Return current src if src is not given
|
||||||
if(!src){ return player.src(); }
|
if(!src){ return player.src(); }
|
||||||
|
@ -160,17 +168,22 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns current resolution
|
* Returns current resolution or sets one when label is specified
|
||||||
* @returns {Object} current resolution object {label: '', sources: []}
|
* @param {String} [label] label name
|
||||||
|
* @returns {Object} current resolution object {label: '', sources: []} if used as getter or player object if used as setter
|
||||||
*/
|
*/
|
||||||
player.currentResolution = function(){
|
player.currentResolution = function(label){
|
||||||
return currentResolution;
|
if(label == null) { return currentResolution; }
|
||||||
|
if(menuItemsHolder[label] != null){
|
||||||
|
menuItemsHolder[label].onClick();
|
||||||
|
}
|
||||||
|
return player;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
* @param {Object} b source object with res property
|
* @param {Object} b - source object with res property
|
||||||
* @returns {Number} result of comparation
|
* @returns {Number} result of comparation
|
||||||
*/
|
*/
|
||||||
function compareResolutions(a, b){
|
function compareResolutions(a, b){
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue