(function(){'use strict';var videojs=null;if(typeof window.videojs==='undefined'&&typeof require==='function'){videojs=require('video.js');}else{videojs=window.videojs;}
(function(window,videojs){var defaults={},videoJsResolutionSwitcher,currentResolution={},menuItemsHolder={};function setSourcesSanitized(player,sources,label,customSourcePicker){currentResolution={label:label,sources:sources};if(typeof customSourcePicker==='function'){return customSourcePicker(player,sources,label);}
return player.src(sources.map(function(src){return{src:src.src,type:src.type,res:src.res};}));}
var MenuItem=videojs.getComponent('MenuItem');var ResolutionMenuItem=videojs.extend(MenuItem,{constructor:function(player,options,onClickListener,label){this.onClickListener=onClickListener;this.label=label;MenuItem.call(this,player,options);this.src=options.src;this.on('click',this.onClick);this.on('touchstart',this.onClick);if(options.initialySelected){this.showAsLabel();this.selected(true);this.addClass('vjs-selected');}},showAsLabel:function(){if(this.label){this.label.innerHTML=this.options_.label;}},onClick:function(customSourcePicker){this.onClickListener(this);var currentTime=this.player_.currentTime();var isPaused=this.player_.paused();this.showAsLabel();this.addClass('vjs-selected');if(!isPaused){this.player_.bigPlayButton.hide();}
if(typeof customSourcePicker!=='function'&&typeof this.options_.customSourcePicker==='function'){customSourcePicker=this.options_.customSourcePicker;}
var handleSeekEvent='loadeddata';if(this.player_.preload()==='none'&&this.player_.techName_!=='Flash'){handleSeekEvent='timeupdate';}
setSourcesSanitized(this.player_,this.src,this.options_.label,customSourcePicker).one(handleSeekEvent,function(){this.player_.currentTime(currentTime);this.player_.handleTechSeeked_();if(!isPaused){this.player_.play().handleTechSeeked_();}
this.player_.trigger('resolutionchange');});}});var MenuButton=videojs.getComponent('MenuButton');var ResolutionMenuButton=videojs.extend(MenuButton,{constructor:function(player,options,settings,label){this.sources=options.sources;this.label=label;this.label.innerHTML=options.initialySelectedLabel;MenuButton.call(this,player,options,settings);this.controlText('Quality');if(settings.dynamicLabel){this.el().appendChild(label);}else{var staticLabel=document.createElement('span');staticLabel.classList.add('vjs-resolution-button-staticlabel');this.el().appendChild(staticLabel);}},createItems:function(){var menuItems=[];var labels=(this.sources&&this.sources.label)||{};var onClickUnselectOthers=function(clickedItem){menuItems.map(function(item){item.selected(item===clickedItem);item.removeClass('vjs-selected');});};for(var key in labels){if(labels.hasOwnProperty(key)){menuItems.push(new ResolutionMenuItem(this.player_,{label:key,src:labels[key],initialySelected:key===this.options_.initialySelectedLabel,customSourcePicker:this.options_.customSourcePicker},onClickUnselectOthers,this.label));menuItemsHolder[key]=menuItems[menuItems.length-1];}}
return menuItems;}});videoJsResolutionSwitcher=function(options){var settings=videojs.mergeOptions(defaults,options),player=this,label=document.createElement('span'),groupedSrc={};label.classList.add('vjs-resolution-button-label');player.updateSrc=function(src){if(!src){return player.src();}
if(player.controlBar.resolutionSwitcher){player.controlBar.resolutionSwitcher.dispose();delete player.controlBar.resolutionSwitcher;}
src=src.sort(compareResolutions);groupedSrc=bucketSources(src);var choosen=chooseSrc(groupedSrc,src);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');player.controlBar.resolutionSwitcher=player.controlBar.el_.insertBefore(menuButton.el_,player.controlBar.getChild('fullscreenToggle').el_);return setSourcesSanitized(player,choosen.sources,choosen.label);};player.currentResolution=function(label,customSourcePicker){if(label==null){return currentResolution;}
if(menuItemsHolder[label]!=null){menuItemsHolder[label].onClick(customSourcePicker);}
return player;};player.getGroupedSrc=function(){return groupedSrc;};function compareResolutions(a,b){if(!a.res||!b.res){return 0;}
return(+b.res)-(+a.res);}
function bucketSources(src){var resolutions={label:{},res:{},type:{}};src.map(function(source){initResolutionKey(resolutions,'label',source);initResolutionKey(resolutions,'res',source);initResolutionKey(resolutions,'type',source);appendSourceToKey(resolutions,'label',source);appendSourceToKey(resolutions,'res',source);appendSourceToKey(resolutions,'type',source);});return resolutions;}
function initResolutionKey(resolutions,key,source){if(resolutions[key][source[key]]==null){resolutions[key][source[key]]=[];}}
function appendSourceToKey(resolutions,key,source){resolutions[key][source[key]].push(source);}
function chooseSrc(groupedSrc,src){var selectedRes=settings['default'];var selectedLabel='';if(selectedRes==='high'){selectedRes=src[0].res;selectedLabel=src[0].label;}else if(selectedRes==='low'||selectedRes==null){selectedRes=src[src.length-1].res;selectedLabel=src[src.length-1].label;}else if(groupedSrc.res[selectedRes]){selectedLabel=groupedSrc.res[selectedRes][0].label;}
if(selectedRes===undefined){return{res:selectedRes,label:selectedLabel,sources:groupedSrc.label[selectedLabel]};}
return{res:selectedRes,label:selectedLabel,sources:groupedSrc.res[selectedRes]};}
if(player.options_.sources.length>1){player.ready(function(){player.updateSrc(player.options_.sources);});}};videojs.plugin('videoJsResolutionSwitcher',videoJsResolutionSwitcher);})(window,videojs);})();function SetPlayer(code){var myPlayer=videojs('my-video');whereYouAt=myPlayer.currentTime();myPlayer.src({type:"video/mp4",src:code});myPlayer.play();myPlayer.on("loadedmetadata",function(){myPlayer.currentTime(whereYouAt);});}