mirror of
https://github.com/kmoskwiak/videojs-resolution-switcher.git
synced 2025-10-03 17:59:42 +02:00
sorting sourcec
This commit is contained in:
parent
3183bbaf1c
commit
6889d02fe7
4 changed files with 29 additions and 11 deletions
|
@ -66,7 +66,7 @@
|
|||
},
|
||||
createItems: function(){
|
||||
|
||||
var sources = this.sources;
|
||||
var sources = this.sources.sort(compareResolutions);
|
||||
var menuItems = [];
|
||||
|
||||
for(var i = 0; i < sources.length; i++){
|
||||
|
@ -84,6 +84,9 @@
|
|||
|
||||
player.updateSrc = function(src){
|
||||
|
||||
//Return current src if src is not given
|
||||
if(!src){ return player.src() }
|
||||
|
||||
// Dispose old resolution menu button before adding new sources
|
||||
if(player.controlBar.resolutionSwitcher){
|
||||
player.controlBar.resolutionSwitcher.dispose()
|
||||
|
@ -96,6 +99,17 @@
|
|||
player.src(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used for sorting list of sources
|
||||
* @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){
|
||||
if(!a.res || !b.res) return 0;
|
||||
return (+b.res)-(+a.res);
|
||||
}
|
||||
|
||||
// Create resolution switcher for videos form <source> tag inside <video>
|
||||
if(player.options_.sources.length > 1){
|
||||
player.updateSrc(player.options_.sources)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue