mirror of
https://github.com/kmoskwiak/videojs-resolution-switcher.git
synced 2025-10-03 09:49:21 +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 = {},
|
||||
videoJsResolutionSwitcher,
|
||||
currentResolution = {};
|
||||
currentResolution = {}, // stores current resolution
|
||||
menuItemsHolder = {}; // stores menuItems
|
||||
|
||||
function setSourcesSanitized(player, sources, label) {
|
||||
currentResolution = {
|
||||
|
@ -70,7 +71,7 @@
|
|||
// Change player source and wait for loadeddata event, then play video
|
||||
// loadedmetadata doesn't work right now for flash.
|
||||
// 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_.handleTechSeeked_();
|
||||
if(!isPaused){
|
||||
|
@ -124,6 +125,8 @@
|
|||
},
|
||||
onClickUnselectOthers,
|
||||
this.label));
|
||||
// Store menu item for API calls
|
||||
menuItemsHolder[key] = menuItems[menuItems.length - 1];
|
||||
}
|
||||
}
|
||||
return menuItems;
|
||||
|
@ -132,7 +135,7 @@
|
|||
|
||||
/**
|
||||
* Initialize the plugin.
|
||||
* @param options (optional) {object} configuration for the plugin
|
||||
* @param {object} [options] configuration for the plugin
|
||||
*/
|
||||
videoJsResolutionSwitcher = function(options) {
|
||||
var settings = videojs.mergeOptions(defaults, options),
|
||||
|
@ -141,6 +144,11 @@
|
|||
|
||||
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){
|
||||
//Return current src if src is not given
|
||||
if(!src){ return player.src(); }
|
||||
|
@ -160,17 +168,22 @@
|
|||
};
|
||||
|
||||
/**
|
||||
* Returns current resolution
|
||||
* @returns {Object} current resolution object {label: '', sources: []}
|
||||
* Returns current resolution or sets one when label is specified
|
||||
* @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(){
|
||||
return currentResolution;
|
||||
player.currentResolution = function(label){
|
||||
if(label == null) { return currentResolution; }
|
||||
if(menuItemsHolder[label] != null){
|
||||
menuItemsHolder[label].onClick();
|
||||
}
|
||||
return player;
|
||||
};
|
||||
|
||||
/**
|
||||
* Method used for sorting list of sources
|
||||
* @param {Object} a source object with res property
|
||||
* @param {Object} b source object with res property
|
||||
* @param {Object} a - source object with res property
|
||||
* @param {Object} b - source object with res property
|
||||
* @returns {Number} result of comparation
|
||||
*/
|
||||
function compareResolutions(a, b){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue