forked from Dash-Industry-Forum/dash.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdash.min.js
More file actions
3 lines (3 loc) · 72.7 KB
/
Copy pathdash.min.js
File metadata and controls
3 lines (3 loc) · 72.7 KB
1
2
3
MediaPlayer=function(a){"use strict";var b,c,d,e,f,g=a,h=!1,i=!1,j=!0,k=function(){return void 0!==c&&void 0!==d},l=function(){if(!h)throw"MediaPlayer not initialized!";if(!this.capabilities.supportsMediaSource())return alert("Your browser does not support the MediaSource API. Please try another browser, such as Chrome."),void 0;if(!c||!d)throw"Missing view or source.";i=!0,this.debug.log("Playback initiated!"),f=b.getObject("stream"),f.load(d)},m=function(){j&&k()&&l.call(this)};return console.log("remove me"),b=new dijon.System,b.mapValue("system",b),b.mapOutlet("system"),b.injectInto(g),{debug:void 0,capabilities:void 0,videoModel:void 0,abrController:void 0,metricsModel:void 0,metricsConverter:void 0,metricsExt:void 0,startup:function(){h||(b.injectInto(this),h=!0)},getMetricsConverter:function(){return this.metricsConverter},getDebug:function(){return this.debug},getVideoModel:function(){return this.videoModel},setAutoPlay:function(a){j=a},getAutoPlay:function(){return j},getIsLive:function(){return this.videoModel.getIsLive()},setIsLive:function(a){this.videoModel.setIsLive(a)},getMetricsExt:function(){return this.metricsExt},getMetricsFor:function(a){var b=this.metricsModel.getReadOnlyMetricsFor(a);return b},getQualityFor:function(a){return this.abrController.getQualityFor(a)},setQualityFor:function(a,b){this.abrController.setPlaybackQuality(a,b)},getAutoSwitchQuality:function(){return this.abrController.getAutoSwitchBitrate()},setAutoSwitchQuality:function(a){this.abrController.setAutoSwitchBitrate(a)},attachView:function(a){if(!h)throw"MediaPlayer not initialized!";c=a,c.autoplay=!0,e=new MediaPlayer.models.VideoModel(c),this.videoModel.setElement(c),i||m.call(this)},attachSource:function(a){if(!h)throw"MediaPlayer not initialized!";d=a,i&&(f.reset(),f=null),m.call(this)},play:l}},MediaPlayer.prototype={constructor:MediaPlayer},MediaPlayer.dependencies={},MediaPlayer.utils={},MediaPlayer.models={},MediaPlayer.vo={},MediaPlayer.vo.metrics={},MediaPlayer.rules={},MediaPlayer.di={},MediaPlayer.di.Context=function(){"use strict";return{system:void 0,setup:function(){this.system.autoMapOutlets=!0,this.system.mapSingleton("debug",MediaPlayer.utils.Debug),this.system.mapSingleton("capabilities",MediaPlayer.utils.Capabilities),this.system.mapSingleton("videoModel",MediaPlayer.models.VideoModel),this.system.mapSingleton("manifestModel",MediaPlayer.models.ManifestModel),this.system.mapSingleton("metricsModel",MediaPlayer.models.MetricsModel),this.system.mapSingleton("mediaSourceExt",MediaPlayer.dependencies.MediaSourceExtensions),this.system.mapSingleton("sourceBufferExt",MediaPlayer.dependencies.SourceBufferExtensions),this.system.mapSingleton("bufferExt",MediaPlayer.dependencies.BufferExtensions),this.system.mapSingleton("abrController",MediaPlayer.dependencies.AbrController),this.system.mapSingleton("errHandler",MediaPlayer.dependencies.ErrorHandler),this.system.mapClass("metrics",MediaPlayer.models.MetricsList),this.system.mapClass("downloadRatioRule",MediaPlayer.rules.DownloadRatioRule),this.system.mapClass("insufficientBufferRule",MediaPlayer.rules.InsufficientBufferRule),this.system.mapClass("limitSwitchesRule",MediaPlayer.rules.LimitSwitchesRule),this.system.mapClass("abrRulesCollection",MediaPlayer.rules.BaseRulesCollection),this.system.mapClass("bufferController",MediaPlayer.dependencies.BufferController),this.system.mapClass("manifestLoader",MediaPlayer.dependencies.ManifestLoader),this.system.mapClass("manifestUpdater",MediaPlayer.dependencies.ManifestUpdater),this.system.mapClass("fragmentController",MediaPlayer.dependencies.FragmentController),this.system.mapClass("fragmentLoader",MediaPlayer.dependencies.FragmentLoader),this.system.mapClass("stream",MediaPlayer.dependencies.Stream)}}},Dash=function(){"use strict";return{modules:{},dependencies:{},vo:{},di:{}}}(),Dash.di.DashContext=function(){"use strict";return{system:void 0,setup:function(){Dash.di.DashContext.prototype.setup.call(this),this.system.mapClass("parser",Dash.dependencies.DashParser),this.system.mapClass("indexHandler",Dash.dependencies.DashHandler),this.system.mapClass("baseURLExt",Dash.dependencies.BaseURLExtensions),this.system.mapClass("fragmentExt",Dash.dependencies.FragmentExtensions),this.system.mapSingleton("manifestExt",Dash.dependencies.DashManifestExtensions),this.system.mapSingleton("metricsExt",Dash.dependencies.DashMetricsExtensions),this.system.mapSingleton("metricsConverter",Dash.dependencies.DashMetricsConverter)}}},Dash.di.DashContext.prototype=new MediaPlayer.di.Context,Dash.di.DashContext.prototype.constructor=Dash.di.DashContext,Dash.dependencies.BaseURLExtensions=function(){"use strict";var a=function(a,b){for(var c,d,e,f,g,h,i,j,k,l,m=b||0,n=new DataView(a),o={},p=m;"sidx"!==j&&p<n.byteLength;){if(k=n.getUint32(p),8>k)throw"box must at least contain size and type fields";if(k>p+n.byteLength)throw"box is larger than the array buffer";for(p+=4,j="",f=0;4>f;f+=1)l=n.getInt8(p),j+=String.fromCharCode(l),p+=1;"moof"!==j&&"traf"!==j&&"sidx"!==j?p+=k-8:"sidx"===j&&(p-=8)}if(e=n.getUint32(p,!1)+p,e>a.byteLength)throw"sidx terminates after array buffer";for(o.version=n.getUint8(p+8),p+=12,o.timescale=n.getUint32(p+4,!1),p+=8,0===o.version?(o.earliest_presentation_time=n.getUint32(p,!1),o.first_offset=n.getUint32(p+4,!1),p+=8):(o.earliest_presentation_time=utils.Math.to64BitNumber(n.getUint32(p+4,!1),n.getUint32(p,!1)),o.first_offset=(n.getUint32(p+8,!1)<<32)+n.getUint32(p+12,!1),p+=16),o.first_offset+=e+m,o.reference_count=n.getUint16(p+2,!1),p+=4,o.references=[],d=o.first_offset,c=o.earliest_presentation_time,f=0;f<o.reference_count;f+=1)h=n.getUint32(p,!1),g=h>>>31,h=2147483647&h,i=n.getUint32(p+4,!1),p+=12,o.references.push({size:h,type:g,offset:d,duration:i,time:c,timescale:o.timescale}),d+=h,c+=i;if(p!==e)throw"Error: final pos "+p+" differs from SIDX end "+e;return o},b=function(b,c,d){var e,f,g,h,i,j,k,l;for(e=a.call(this,b,d),f=e.references,g=[],i=0,j=f.length;j>i;i+=1)h=new Dash.vo.Segment,h.duration=f[i].duration,h.media=c,h.startTime=f[i].time,h.timescale=f[i].timescale,k=f[i].offset,l=f[i].offset+f[i].size-1,h.mediaRange=k+"-"+l,g.push(h);return this.debug.log("Parsed SIDX box: "+g.length+" segments."),Q.when(g)},c=function(a,b){var d,e,f,g,h,i,j,k=Q.defer(),l=new DataView(a),m=0,n="",o=0,p=!1,q=this;for(q.debug.log("Searching for initialization.");"moov"!==n&&m<l.byteLength;){for(o=l.getUint32(m),m+=4,n="",g=0;4>g;g+=1)h=l.getInt8(m),n+=String.fromCharCode(h),m+=1;"moov"!==n&&(m+=o-8)}return f=l.byteLength-m,"moov"!==n?(q.debug.log("Loading more bytes to find initialization."),b.range.start=0,b.range.end=b.bytesLoaded+b.bytesToLoad,i=new XMLHttpRequest,i.onloadend=function(){p||k.reject("Error loading initialization.")},i.onload=function(){p=!0,b.bytesLoaded=b.range.end,c.call(q,i.response).then(function(a){k.resolve(a)})},i.onerror=function(){k.reject("Error loading initialization.")},i.open("GET",b.url),i.responseType="arraybuffer",i.setRequestHeader("Range","bytes="+b.range.start+"-"+b.range.end),i.send(null)):(d=m-8,e=d+o-1,j=d+"-"+e,q.debug.log("Found the initialization. Range: "+j),k.resolve(j)),k.promise},d=function(a){var b=Q.defer(),d=new XMLHttpRequest,e=!1,f=this,g={url:a,range:{},searching:!1,bytesLoaded:0,bytesToLoad:1500,request:d};return f.debug.log("Start searching for initialization."),g.range.start=0,g.range.end=g.bytesToLoad,d.onloadend=function(){e||b.reject("Error finding initialization.")},d.onload=function(){e=!0,g.bytesLoaded=g.range.end,c.call(f,d.response,g).then(function(a){b.resolve(a)})},d.onerror=function(){b.reject("Error finding initialization.")},d.open("GET",g.url),d.responseType="arraybuffer",d.setRequestHeader("Range","bytes="+g.range.start+"-"+g.range.end),d.send(null),f.debug.log("Perform init search: "+g.url),b.promise},e=function(a,c){var d,f,g,h,i,j,k,l,m=Q.defer(),n=new DataView(a),o=new XMLHttpRequest,p=0,q="",r=0,s=!1,t=!1,u=this;for(u.debug.log("Searching for SIDX box."),u.debug.log(c.bytesLoaded+" bytes loaded.");"sidx"!==q&&p<n.byteLength;){for(r=n.getUint32(p),p+=4,q="",i=0;4>i;i+=1)j=n.getInt8(p),q+=String.fromCharCode(j),p+=1;"sidx"!==q&&(p+=r-8)}if(d=n.byteLength-p,"sidx"!==q)throw"Could not find SIDX box!";if(r-8>d)u.debug.log("Found SIDX but we don't have all of it."),c.range.start=0,c.range.end=c.bytesLoaded+(r-d),o.onloadend=function(){s||m.reject("Error loading sidx.")},o.onload=function(){s=!0,c.bytesLoaded=c.range.end,e.call(u,o.response,c).then(function(a){m.resolve(a)})},o.onerror=function(){m.reject("Error loading sidx.")},o.open("GET",c.url),o.responseType="arraybuffer",o.setRequestHeader("Range","bytes="+c.range.start+"-"+c.range.end),o.send(null);else if(c.range.start=p-8,c.range.end=c.range.start+r,u.debug.log("Found the SIDX box. Start: "+c.range.start+" | End: "+c.range.end),f=new ArrayBuffer(c.range.end-c.range.start),h=new Uint8Array(f),g=new Uint8Array(a,c.range.start,c.range.end-c.range.start),h.set(g),k=this.parseSIDX.call(this,f),l=k.references,null!==l&&void 0!==l&&l.length>0&&(t=1===l[0].type),t){u.debug.log("Initiate multiple SIDX load.");var v,w,x,y,z,A,B=[];for(v=0,w=l.length;w>v;v+=1)x=l[v].offset,y=l[v].offset+l[v].size-1,z=x+"-"+y,B.push(this.loadSegments.call(u,c.url,z));Q.all(B).then(function(a){for(A=[],v=0,w=a.length;w>v;v+=1)A=A.concat(a[v]);m.resolve(A)})}else u.debug.log("Parsing segments from SIDX."),b.call(u,f,c.url).then(function(a){m.resolve(a)});return m.promise},f=function(a,c){var d,f=Q.defer(),g=new XMLHttpRequest,h=!1,i=this,j={url:a,range:{},searching:!1,bytesLoaded:0,bytesToLoad:1500,request:g};return null===c?(i.debug.log("No known range for SIDX request."),j.searching=!0,j.range.start=0,j.range.end=j.bytesToLoad):(d=c.split("-"),j.range.start=parseFloat(d[0]),j.range.end=parseFloat(d[1])),g.onloadend=function(){h||f.reject("Error loading sidx.")},g.onload=function(){h=!0,j.searching?(j.bytesLoaded=j.range.end,e.call(i,g.response,j).then(function(a){f.resolve(a)})):b.call(i,g.response,j.url).then(function(a){f.resolve(a)})},g.onerror=function(){f.reject("Error loading sidx.")},g.open("GET",j.url),g.responseType="arraybuffer",g.setRequestHeader("Range","bytes="+j.range.start+"-"+j.range.end),g.send(null),i.debug.log("Perform SIDX load ("+c+"): "+j.url),f.promise};return{debug:void 0,loadSegments:f,loadInitialization:d,parseSegments:b,parseSIDX:a,findSIDX:e}},Dash.dependencies.BaseURLExtensions.prototype={constructor:Dash.dependencies.BaseURLExtensions},Dash.dependencies.DashHandler=function(){"use strict";var a,b,c,d=-1,e=function(a,b){var c=null;return b&&b.Representation_asArray&&b.Representation_asArray.length>0&&(c=b.Representation_asArray[a]),c},f=function(a,b){var c=b.toString();return a.split("$Number$").join(c)},g=function(a,b){var c=b.toString();return a.split("$Time$").join(c)},h=function(a,b){var c=b.toString();return a.split("$Bandwidth$").join(c)},i=function(a,b){if(null===b||-1===a.indexOf("$RepresentationID$"))return a;var c=b.toString();return a.split("$RepresentationID$").join(c)},j=function(a,b){var c;return c=a===b?a:-1!==a.indexOf("http://")?a:b+a},k=function(a,b){var d=Q.defer(),f=e(a,b),g=null,k=null,l=null,m=null,n=this;return n.debug.log("Getting the initialization request."),f.hasOwnProperty("SegmentTemplate")?f.SegmentTemplate.hasOwnProperty("initialization")&&(k=f.SegmentTemplate.initialization,k=h(k,f.bandwidth),k=i(k,f.id)):f.hasOwnProperty("SegmentList")&&f.SegmentList.hasOwnProperty("Initialization")&&f.SegmentList.Initialization.hasOwnProperty("sourceURL")?k=f.SegmentList.Initialization.sourceURL:f.hasOwnProperty("SegmentBase")&&f.SegmentBase.hasOwnProperty("Initialization")&&f.SegmentBase.Initialization.hasOwnProperty("range")?(k=f.BaseURL,m=f.SegmentBase.Initialization.range):(l=f.BaseURL,n.baseURLExt.loadInitialization(l).then(function(a){n.debug.log("Got an initialization."),g=new MediaPlayer.vo.SegmentRequest,g.streamType=c,g.type="Initialization Segment",g.url=j(l,f.BaseURL),g.range=a,d.resolve(g)},function(){n.errHandler.downloadError("Error loading initialization.")})),k&&k.length>0&&(n.debug.log("Got an initialization."),g=new MediaPlayer.vo.SegmentRequest,g.streamType=c,g.type="Initialization Segment",g.url=j(k,f.BaseURL),g.range=m,d.resolve(g)),d.promise},l=function(c){var e,f,g,h,i=!1;return this.debug.log("Checking for stream end..."),a?(this.debug.log("Live never ends! (TODO)"),i=!1):c.hasOwnProperty("segments")&&null!==c.segments?(this.debug.log("Segments: "+d+" / "+c.segments.length),i=d>=c.segments.length):c.hasOwnProperty("SegmentTemplate")&&!c.SegmentTemplate.hasOwnProperty("SegmentTimeline")&&(f=1,h=Math.floor(b),c.SegmentTemplate.hasOwnProperty("duration")&&(e=c.SegmentTemplate.duration,c.SegmentTemplate.hasOwnProperty("timescale")&&(f=c.SegmentTemplate.timescale),g=e/f,this.debug.log("SegmentTemplate: "+g+" * "+d+" = "+g*d+" / "+h),i=g*d>=h)),Q.when(i)},m=function(a,b){var c,d,e,h,i,j,k,l,m=[],n=0,o=1,p=1;for(a.hasOwnProperty("startNumber")&&(o=a.startNumber),a.hasOwnProperty("timescale")&&(p=a.timescale),c=b.S_asArray,e=0,h=c.length;h>e;e+=1)for(d=c[e],j=0,d.hasOwnProperty("r")&&(j=d.r),i=0;j>=i;i+=1)k=new Dash.vo.Segment,k.timescale=p,d.hasOwnProperty("t")?(k.startTime=d.t,n=d.t):k.startTime=n,k.duration=d.d,l=a.media,l=f(l,o),l=g(l,k.startTime),k.media=l,m.push(k),n+=k.duration,o+=1;return Q.when(m)},n=function(a){var b,c,d,e,f,g=[],h=1;for(a.hasOwnProperty("startNumber")&&(h=Math.max(a.startNumber,1)),f=(h-1)*a.duration,b=0,c=a.SegmentURL_asArray.length;c>b;b+=1)e=a.SegmentURL_asArray[b],d=new Dash.vo.Segment,d.media=e.media,d.mediaRange=e.mediaRange,d.index=e.index,d.indexRange=e.indexRange,d.timescale=a.timescale,d.duration=a.duration,d.startTime=f+b*a.duration,g.push(d);return Q.when(g)},o=function(a){var b=a.BaseURL,c=null;return a.hasOwnProperty("SegmentBase")&&a.SegmentBase.hasOwnProperty("indexRange")&&(c=a.SegmentBase.indexRange),this.baseURLExt.loadSegments(b,c)},p=function(a){var b;return b=a.hasOwnProperty("SegmentTemplate")&&!a.SegmentTemplate.hasOwnProperty("SegmentTimeline")?Q.when(null):a.hasOwnProperty("segments")&&null!==a.segments?Q.when(a.segments):a.hasOwnProperty("SegmentTemplate")&&a.SegmentTemplate.hasOwnProperty("SegmentTimeline")?m.call(this,a.SegmentTemplate,a.SegmentTemplate.SegmentTimeline):a.hasOwnProperty("SegmentList")?n.call(this,a.SegmentList):o.call(this,a)},q=function(a,b){var c,d,e,f,g=-1;if(b&&b.length>0)for(f=b.length-1;f>=0;f--)if(c=b[f],d=c.startTime/c.timescale,e=c.duration/c.timescale,a>=d&&d+e>=a){g=f;break}return-1===g&&(console.log("Couldn't figure out a time!"),console.log("Time: "+a),console.log(b)),Q.when(g)},r=function(a,b){var c,d,e=-1,f=1,g=1;if(!b.hasOwnProperty("duration"))throw"Expected 'duration' attribute on SegmentTemplate!";return c=b.duration,b.hasOwnProperty("timescale")&&(f=b.timescale),b.hasOwnProperty("startNumber")&&(g=b.startNumber),d=c/f,e=Math.floor(a/d),e+=g,Q.when(e)},s=function(a,b,d){var e,k,l=new MediaPlayer.vo.SegmentRequest,m=1;return b.hasOwnProperty("timescale")&&(m=b.timescale),k=b.duration*a/m,k=Math.floor(k),e=b.media,e=f(e,a),e=g(e,k),e=h(e,d.bandwidth),e=i(e,d.id),l.streamType=c,l.type="Media Segment",l.url=j(e,d.BaseURL),l.duration=b.duration/m,l.timescale=m,l.startTime=a*b.duration/m,Q.when(l)},t=function(a,b,d){if(null===b||void 0===b)return Q.when(null);var e,k=new MediaPlayer.vo.SegmentRequest;return e=j(b.media,d.BaseURL),e=f(e,a),e=g(e,b.startTime),e=h(e,d.bandwidth),e=i(e,d.id),k.streamType=c,k.type="Media Segment",k.url=e,k.range=b.mediaRange,k.startTime=b.startTime/b.timescale,k.duration=b.duration/b.timescale,k.timescale=b.timescale,Q.when(k)},u=function(a,b,c){var f,g,h,i=e(b,c),j=!1,k=this;return k.debug.log("Getting the request for time: "+a),f=Q.defer(),p.call(k,i).then(function(b){var c;if(k.debug.log("Got segments."),k.debug.log(b),null===b){if(!i.hasOwnProperty("SegmentTemplate"))throw"Expected SegmentTemplate!";j=!0,k.debug.log("No segments found, so we must be using a SegmentTemplate."),c=r.call(k,a,i.SegmentTemplate)}else k.debug.log("Got a list of segments, so dig deeper."),i.segments=b,j=!1,c=q.call(k,a,b);return c}).then(function(b){return k.debug.log("Index for time "+a+" is "+b),d=b,l.call(k,i)}).then(function(a){var b=null;return k.debug.log("Stream finished? "+a),a?(g=new MediaPlayer.vo.SegmentRequest,g.action=g.ACTION_COMPLETE,k.debug.log("Signal complete."),k.debug.log(g),f.resolve(g)):j?b=s.call(k,d,i.SegmentTemplate,i):(h=i.segments[d],b=t.call(k,d,h,i)),b}).then(function(a){k.debug.log("Got a request."),k.debug.log(a),f.resolve(a)}),f.promise},v=function(a,b){var c,f,g,h=e(a,b),i=this;if(i.debug.log("Getting the next request."),-1===d)throw"You must call getSegmentRequestForTime first.";return d+=1,i.debug.log("New index: "+d),c=Q.defer(),l.call(i,h).then(function(a){i.debug.log("Stream finished? "+a),a?(f=new MediaPlayer.vo.SegmentRequest,f.action=f.ACTION_COMPLETE,i.debug.log("Signal complete."),i.debug.log(f),c.resolve(f)):p.call(i,h).then(function(a){var b;if(i.debug.log("Got segments."),i.debug.log(a),null===a){if(!h.hasOwnProperty("SegmentTemplate"))throw"Expected SegmentTemplate!";i.debug.log("No segments found, so we must be using a SegmentTemplate."),b=s.call(i,d,h.SegmentTemplate,h)}else h.segments=a,g=h.segments[d],b=t.call(i,d,g,h);return b}).then(function(a){i.debug.log("Got a request."),i.debug.log(a),c.resolve(a)})}),c.promise},w=function(a,b){if(-1===d)return Q.when(0);var c,f,g,h,i,j=e(a,b),k=1,l=Q.defer();return g=d,0>g&&(g=0),p.call(c,j).then(function(a){if(null===a||void 0===a){if(!j.hasOwnProperty("SegmentTemplate"))throw"Expected SegmentTemplate!";i=j.SegmentTemplate.duration,j.SegmentTemplate.hasOwnProperty("timescale")&&(k=j.SegmentTemplate.timescale),f=i/k*g}else g>=a.length&&(g=a.length-1),h=a[g].startTime,i=a[g].duration,a[g].hasOwnProperty("timescale")&&(k=a[g].timescale),f=h/k;l.resolve(f)}),l.promise};return{debug:void 0,baseURLExt:void 0,manifestModel:void 0,errHandler:void 0,getType:function(){return c},setType:function(a){c=a},getIsLive:function(){return a},setIsLive:function(b){a=b},getDuration:function(){return b},setDuration:function(a){b=a},getInitRequest:k,getSegmentRequestForTime:u,getNextSegmentRequest:v,getCurrentTime:w}},Dash.dependencies.DashHandler.prototype={constructor:Dash.dependencies.DashHandler},Dash.dependencies.DashManifestExtensions=function(){"use strict"},Dash.dependencies.DashManifestExtensions.prototype={constructor:Dash.dependencies.DashManifestExtensions,getIsAudio:function(a){"use strict";var b,c,d,e=a.ContentComponent_asArray,f=!1,g=!1;if(e)for(b=0,c=e.length;c>b;b+=1)"audio"===e[b].contentType&&(f=!0,g=!0);if(a.hasOwnProperty("mimeType")&&(f=-1!==a.mimeType.indexOf("audio"),g=!0),!g)for(b=0,c=a.Representation_asArray.length;!g&&c>b;)d=a.Representation_asArray[b],d.hasOwnProperty("mimeType")&&(f=-1!==d.mimeType.indexOf("audio"),g=!0),b+=1;return Q.when(f)},getIsVideo:function(a){"use strict";var b,c,d,e=a.ContentComponent_asArray,f=!1,g=!1;if(e)for(b=0,c=e.length;c>b;b+=1)"video"===e[b].contentType&&(f=!0,g=!0);if(a.hasOwnProperty("mimeType")&&(f=-1!==a.mimeType.indexOf("video"),g=!0),!g)for(b=0,c=a.Representation_asArray.length;!g&&c>b;)d=a.Representation_asArray[b],d.hasOwnProperty("mimeType")&&(f=-1!==d.mimeType.indexOf("video"),g=!0),b+=1;return Q.when(f)},getIsMain:function(){"use strict";return Q.when(!1)},processAdaptation:function(a){"use strict";return void 0!==a.Representation_asArray&&null!==a.Representation_asArray&&a.Representation_asArray.sort(function(a,b){return a.bandwidth-b.bandwidth}),a},getDataForId:function(a,b){"use strict";var c,d,e=b.Period_asArray[0].AdaptationSet_asArray;for(c=0,d=e.length;d>c;c+=1)if(e[c].hasOwnProperty("id")&&e[c].id===a)return Q.when(e[c]);return Q.when(null)},getDataForIndex:function(a,b){"use strict";var c=b.Period_asArray[0].AdaptationSet_asArray;return Q.when(c[a])},getDataIndex:function(a,b){"use strict";var c,d,e=b.Period_asArray[0].AdaptationSet_asArray;for(c=0,d=e.length;d>c;c+=1)if(e[c]===a)return Q.when(c);return Q.when(-1)},getVideoData:function(a){"use strict";var b,c,d=this,e=a.Period_asArray[0].AdaptationSet_asArray,f=Q.defer(),g=[];for(b=0,c=e.length;c>b;b+=1)g.push(this.getIsVideo(e[b]));return Q.all(g).then(function(a){var g=!1;for(b=0,c=a.length;c>b;b+=1)a[b]===!0&&(g=!0,f.resolve(d.processAdaptation(e[b])));g||f.resolve(null)}),f.promise},getAudioDatas:function(a){"use strict";var b,c,d=this,e=a.Period_asArray[0].AdaptationSet_asArray,f=Q.defer(),g=[];for(b=0,c=e.length;c>b;b+=1)g.push(this.getIsAudio(e[b]));return Q.all(g).then(function(a){var g=[];for(b=0,c=a.length;c>b;b+=1)a[b]===!0&&g.push(d.processAdaptation(e[b]));f.resolve(g)}),f.promise},getPrimaryAudioData:function(a){"use strict";var b,c,d=Q.defer(),e=[],f=this;return this.getAudioDatas(a).then(function(a){for(a&&0!==a.length||d.resolve(null),b=0,c=a.length;c>b;b+=1)e.push(f.getIsMain(a[b]));Q.all(e).then(function(e){var g=!1;for(b=0,c=e.length;c>b;b+=1)e[b]===!0&&(g=!0,d.resolve(f.processAdaptation(a[b])));g||d.resolve(a[0])})}),d.promise},getCodec:function(a){"use strict";var b=a.Representation_asArray[0],c=b.mimeType+';codecs="'+b.codecs+'"';return Q.when(c)},getSegmentInfoFor:function(a){return a.hasOwnProperty("SegmentBase")?a.SegmentBase:a.hasOwnProperty("SegmentList")?a.SegmentList:a.hasOwnProperty("SegmentTemplate")?a.SegmentTemplate:null},getLiveOffset:function(a){"use strict";var b=15;return a.hasOwnProperty("suggestedPresentationDelay")&&(b=a.suggestedPresentationDelay),Q.when(b)},getLiveStart:function(a){var b,c,d=0,e=1,f=1,g=null,h=null;return c=a.Period_asArray[0].AdaptationSet_asArray[1].Representation_asArray[0],c.hasOwnProperty("SegmentList")?(g=c.SegmentList,g.hasOwnProperty("startNumber")&&(e=Math.max(g.startNumber,1)),g.hasOwnProperty("timescale")&&(f=g.timescale),b=g.duration,d=(e-1)*b/f):c.hasOwnProperty("SegmentTemplate")&&(h=c.SegmentTemplate,h.hasOwnProperty("startNumber")&&(e=Math.max(h.startNumber,1)),h.hasOwnProperty("timescale")&&(f=h.timescale),b=h.duration,d=h.hasOwnProperty("SegmentTimeline")?h.SegmentTimeline.S_asArray[0].t/f:(e-1)*b/f),Q.when(d)},getLiveEdge:function(a){"use strict";var b,c=this,d=Q.defer(),e=0,f=new Date,g=a.availabilityStartTime;return c.getLiveOffset(a).then(function(h){a.hasOwnProperty("availabilityEndTime")?(b=a.availabilityEndTime,e=(b.getTime()-g.getTime())/1e3):e=(f.getTime()-g.getTime())/1e3,c.getLiveStart(a).then(function(a){e+=a,e-=h,d.resolve(e)})}),d.promise},getPresentationOffset:function(a){var b,c,d,e=0,f=1;return c=a.Period_asArray[0].AdaptationSet_asArray[0].Representation_asArray[0],d=this.getSegmentInfoFor(c),null!==d&&void 0!==d&&d.hasOwnProperty("presentationTimeOffset")&&(b=d.presentationTimeOffset,d.hasOwnProperty("timescale")&&(f=d.timescale),e=b/f),Q.when(e)},getIsDVR:function(a,b){"use strict";var c,d;return c=!isNaN(a.timeShiftBufferDepth),d=b&&c,Q.when(d)},getIsOnDemand:function(a){"use strict";var b=!1;return a.profiles&&a.profiles.length>0&&(b=-1!==a.profiles.indexOf("urn:mpeg:dash:profile:isoff-on-demand:2011")),Q.when(b)},getDuration:function(a,b){"use strict";var c=0/0;return b?c=Number.POSITIVE_INFINITY:a.mediaPresentationDuration?c=a.mediaPresentationDuration:a.availabilityEndTime&&a.availabilityStartTime&&(c=a.availabilityEndTime.getTime()-a.availabilityStartTime.getTime()),Q.when(c)},getBandwidth:function(a){"use strict";return Q.when(a.bandwidth)},getRefreshDelay:function(a){"use strict";var b=0/0;return a.hasOwnProperty("minimumUpdatePeriod")&&(b=parseFloat(a.minimumUpdatePeriod)),Q.when(b)},getRepresentationCount:function(a){"use strict";return Q.when(a.Representation_asArray.length)},getRepresentationFor:function(a,b){"use strict";return Q.when(b.Representation_asArray[a])}},Dash.dependencies.DashMetricsConverter=function(){"use strict";var a=function(a){var b,c,d,e,f,g=[];for(f=0;f<a.length;f+=1)c=a[f],b={},b.text="Buffer: "+(f+1),b.items=[],d={},d.text="t: "+c.t,e={},e.text="level: "+c.level,b.items.push(d),b.items.push(e),g.push(b);return g},b=function(a){var b,c,d,e,f,g,h,i,j,k=[];for(j=0;j<a.length;j+=1)c=a[j],b={},b.text="Trace: "+(j+1),b.items=[],d={},d.text="representationid: "+c.representationid,e={},e.text="subreplevel: "+c.subreplevel,f={},f.text="start: "+c.start,g={},g.text="duration: "+c.duration,h={},h.text="playbackspeed: "+c.playbackspeed,i={},i.text="stopreason: "+c.stopreason,b.items.push(d),b.items.push(e),b.items.push(f),b.items.push(g),b.items.push(h),b.items.push(i),k.push(b);return k},c=function(a){var c,d,e,f,g,h,i,j=[];for(i=0;i<a.length;i+=1)d=a[i],c={},c.text="PlayList: "+(i+1),c.items=[],e={},e.text="start: "+d.start,f={},f.text="mstart: "+d.mstart,g={},g.text="starttype: "+d.starttype,h={},h.text="trace",h.items=b(d.trace),c.items.push(e),c.items.push(f),c.items.push(g),c.items.push(h),j.push(c);return j},d=function(a){var b,c,d,e,f,g,h,i=[];for(h=0;h<a.length;h+=1)c=a[h],b={},b.text="Representation Switch: "+(h+1),b.items=[],d={},d.text="t: "+c.t,e={},e.text="mt: "+c.mt,f={},f.text="to: "+c.to,g={},g.text="lto: "+c.lto,b.items.push(d),b.items.push(e),b.items.push(f),b.items.push(g),i.push(b);return i},e=function(a){var b,c,d,e,f,g=[];for(f=0;f<a.length;f+=1)c=a[f],b={},b.text="DroppedFrame: "+(f+1),b.items=[],d={},d.text="time: "+c.time,e={},e.text="droppedFrames: "+c.droppedFrames,b.items.push(d),b.items.push(e),g.push(b);return g},f=function(a){var b,c,d,e,f,g,h=[];for(g=0;g<a.length;g+=1)c=a[g],b={},b.text="Trace: "+(g+1),b.items=[],d={},d.text="s: "+c.s,e={},e.text="d: "+c.d,f={},f.text="b: "+c.b.toString(),b.items.push(d),b.items.push(e),b.items.push(f),h.push(b)},g=function(a){var b,c,d,e,g,h,i,j,k,l,m,n,o,p,q=[];for(p=0;p<a.length;p+=1)c=a[p],b={},b.text="Http Request: "+(p+1),b.items=[],d={},d.text="tcpid: "+c.tcpid,e={},e.text="type: "+c.type,g={},g.text="url: "+c.url,h={},h.text="actualurl: "+c.actualurl,i={},i.text="range: "+c.range,j={},j.text="trequest: "+c.trequest,k={},k.text="tresponse: "+c.tresponse,l={},l.text="responsecode: "+c.responsecode,m={},m.text="interval: "+c.interval,n={},n.text="mediaduration: "+c.mediaduration,o={},o.text="trace",o.items=f(c.trace),b.items.push(d),b.items.push(e),b.items.push(g),b.items.push(h),b.items.push(i),b.items.push(j),b.items.push(k),b.items.push(l),b.items.push(m),b.items.push(n),b.items.push(o),q.push(b);return q},h=function(a){var b,c,d,e,f,g,h,i,j=[];for(i=0;i<a.length;i+=1)c=a[i],b={},b.text="TCP Connection: "+(i+1),b.items=[],d={},d.text="tcpid: "+c.tcpid,e={},e.text="dest: "+c.dest,f={},f.text="topen: "+c.topen,g={},g.text="tclose: "+c.tclose,h={},h.text="tconnect: "+c.tconnect,b.items.push(d),b.items.push(e),b.items.push(f),b.items.push(g),b.items.push(h),j.push(b);return j},i=function(b){var f,i=a(b.BufferLevel),j=c(b.PlayList),k=d(b.RepSwitchList),l=e(b.DroppedFrames),m=g(b.HttpList),n=h(b.TcpList);return f=new kendo.data.HierarchicalDataSource({data:[{text:"Buffer Level",items:i},{text:"Representation Switch",items:k},{text:"Dropped Frames",items:l},{text:"Play List",items:j},{text:"HTTP Request",items:m},{text:"TCP Connection",items:n}]})};return{toTreeViewDataSource:i}},Dash.dependencies.DashMetricsConverter.prototype={constructor:Dash.dependencies.DashMetricsConverter},Dash.dependencies.DashMetricsExtensions=function(){"use strict";var a=function(a,b){var c,d,e,f,g,h,i,j;for(h=0;h<a.length;h+=1)for(c=a[h],e=c.AdaptationSet_asArray,i=0;i<e.length;i+=1)for(d=e[i],g=d.Representation_asArray,j=0;j<g.length;j+=1)if(f=g[j],b===f.id)return j;return-1},b=function(a,b){var c,d,e,f,g,h,i,j;for(h=0;h<a.length;h+=1)for(c=a[h],e=c.AdaptationSet_asArray,i=0;i<e.length;i+=1)for(d=e[i],g=d.Representation_asArray,j=0;j<g.length;j+=1)if(f=g[j],b===f.id)return f;return null},c=function(a,b){var c,d,e=!1,f=!1,g=!1;return a.hasOwnProperty("mimeType")?c=a.mimeType:a.hasOwnProperty("ContentComponent")&&(d=a.ContentComponent,c=d.contentType),void 0!==c&&null!==c&&(c=c.toLowerCase(),e=!0),void 0!==b&&null!==b&&(b=b.toLowerCase(),f=!0),e&&f&&-1!==c.indexOf(b)&&(g=!0),g},d=function(a,b){var d,e,f,g,h,i;for(h=0;h<a.length;h+=1)for(d=a[h],f=d.AdaptationSet_asArray,i=0;i<f.length;i+=1)if(e=f[i],g=e.Representation_asArray,c(e,b))return g.length;return-1},e=function(a){var c,d=this,e=d.manifestModel.getValue(),f=e.Period_asArray;return c=b.call(d,f,a),null===c?null:c.bandwidth},f=function(b){var c,d=this,e=d.manifestModel.getValue(),f=e.Period_asArray;return c=a.call(d,f,b)},g=function(a){var b,c=this,e=c.manifestModel.getValue(),f=e.Period_asArray;return b=d(f,a)},h=function(a){if(null===a)return null;var b,c,d,e=a.RepSwitchList;return null===e||e.length<=0?null:(b=e.length,c=b-1,d=e[c])},i=function(a){if(null===a)return null;var b,c,d,e=a.BufferLevel;return null===e||e.length<=0?null:(b=e.length,c=b-1,d=e[c])},j=function(a){if(null===a)return null;var b,c,d,e=a.HttpList;return null===e||e.length<=0?null:(b=e.length,c=b-1,d=e[c])},k=function(a){if(null===a)return null;var b,c,d,e=a.DroppedFrames;return null===e||e.length<=0?null:(b=e.length,c=b-1,d=e[c])};return{manifestModel:void 0,getBandwidthForRepresentation:e,getIndexForRepresentation:f,getMaxIndexForBufferType:g,getCurrentRepresentationSwitch:h,getCurrentBufferLevel:i,getCurrentHttpRequest:j,getCurrentDroppedFrames:k}},Dash.dependencies.DashMetricsExtensions.prototype={constructor:Dash.dependencies.DashMetricsExtensions},Dash.dependencies.DashParser=function(){"use strict";var a=31536e3,b=2592e3,c=86400,d=3600,e=60,f=/P(([\d.]*)Y)?(([\d.]*)M)?(([\d.]*)D)?T(([\d.]*)H)?(([\d.]*)M)?(([\d.]*)S)?/,g=/^(\d{4}\-\d\d\-\d\d([tT][\d:\.]*)?)([zZ]|([+\-])(\d\d):(\d\d))?$/,h=/^[-+]?[0-9]+[.]?[0-9]*([eE][-+]?[0-9]+)?$/,i=[{type:"duration",test:function(a){return f.test(a)},converter:function(g){var h=f.exec(g);return parseFloat(h[2]||0)*a+parseFloat(h[4]||0)*b+parseFloat(h[6]||0)*c+parseFloat(h[8]||0)*d+parseFloat(h[10]||0)*e+parseFloat(h[12]||0)}},{type:"datetime",test:function(a){return g.test(a)},converter:function(a){return new Date(a)}},{type:"numeric",test:function(a){return h.test(a)},converter:function(a){return parseFloat(a)}}],j=function(){var a,b,c,d;return d=[{name:"profiles",merge:!1},{name:"width",merge:!1},{name:"height",merge:!1},{name:"sar",merge:!1},{name:"frameRate",merge:!1},{name:"audioSamplingRate",merge:!1},{name:"mimeType",merge:!1},{name:"segmentProfiles",merge:!1},{name:"codecs",merge:!1},{name:"maximumSAPPeriod",merge:!1},{name:"startsWithSap",merge:!1},{name:"maxPlayoutRate",merge:!1},{name:"codingDependency",merge:!1},{name:"scanType",merge:!1},{name:"FramePacking",merge:!0},{name:"AudioChannelConfiguration",merge:!0},{name:"ContentProtection",merge:!0}],a={},a.name="AdaptationSet",a.isRoot=!1,a.isArray=!0,a.parent=null,a.children=[],a.properties=d,b={},b.name="Representation",b.isRoot=!1,b.isArray=!0,b.parent=a,b.children=[],b.properties=d,a.children.push(b),c={},c.name="SubRepresentation",c.isRoot=!1,c.isArray=!0,c.parent=b,c.children=[],c.properties=d,b.children.push(c),a},k=function(){var a,b,c,d;return d=[{name:"SegmentBase",merge:!0},{name:"SegmentTemplate",merge:!0},{name:"SegmentList",merge:!0}],a={},a.name="Period",a.isRoot=!1,a.isArray=!0,a.parent=null,a.children=[],a.properties=d,b={},b.name="AdaptationSet",b.isRoot=!1,b.isArray=!0,b.parent=a,b.children=[],b.properties=d,a.children.push(b),c={},c.name="Representation",c.isRoot=!1,c.isArray=!0,c.parent=b,c.children=[],c.properties=d,b.children.push(c),a},l=function(){var a,b,c,d,e;return e=[{name:"BaseURL",merge:!0,mergeFunction:function(a,b){var c;return c=0===b.indexOf("http://")?b:a+b}}],a={},a.name="mpd",a.isRoot=!0,a.isArray=!0,a.parent=null,a.children=[],a.properties=e,b={},b.name="Period",b.isRoot=!1,b.isArray=!0,b.parent=null,b.children=[],b.properties=e,a.children.push(b),c={},c.name="AdaptationSet",c.isRoot=!1,c.isArray=!0,c.parent=b,c.children=[],c.properties=e,b.children.push(c),d={},d.name="Representation",d.isRoot=!1,d.isArray=!0,d.parent=c,d.children=[],d.properties=e,c.children.push(d),a},m=function(){var a=[];return a.push(j()),a.push(k()),a.push(l()),a},n=function(a,b){this.debug.log("Doing parse.");var c,d=new X2JS(i,"",!0),e=new ObjectIron(m());
return this.debug.log("Converting from XML."),c=d.xml_str2json(a),c.hasOwnProperty("BaseURL")||(this.debug.log("Setting baseURL: "+b),c.BaseURL=b),0!==c.BaseURL.indexOf("http")&&(c.BaseURL=b+c.BaseURL),this.debug.log("Flatten manifest properties."),e.run(c),this.debug.log("Parsing complete."),Q.when(c)};return{debug:void 0,parse:n}},Dash.dependencies.DashParser.prototype={constructor:Dash.dependencies.DashParser},Dash.dependencies.FragmentExtensions=function(){"use strict";var a=function(a){for(var b,c,d,e,f,g,h=Q.defer(),i=new DataView(a),j=0;"tfdt"!==e&&j<i.byteLength;){for(d=i.getUint32(j),j+=4,e="",f=0;4>f;f+=1)g=i.getInt8(j),e+=String.fromCharCode(g),j+=1;"moof"!==e&&"traf"!==e&&"tfdt"!==e&&(j+=d-8)}if(j===i.byteLength)throw"Error finding live offset.";return c=i.getUint8(j),this.debug.log("position: "+j),0===c?(j+=4,b=i.getUint32(j,!1)):(j+=d-16,b=utils.Math.to64BitNumber(i.getUint32(j+4,!1),i.getUint32(j,!1))),h.resolve({version:c,base_media_decode_time:b}),h.promise},b=function(a){for(var b,c,d,e,f,g,h,i=new DataView(a),j=0;"sidx"!==f&&j<i.byteLength;){for(g=i.getUint32(j),j+=4,f="",e=0;4>e;e+=1)h=i.getInt8(j),f+=String.fromCharCode(h),j+=1;"moof"!==f&&"traf"!==f&&"sidx"!==f?j+=g-8:"sidx"===f&&(j-=8)}return b=i.getUint8(j+8),j+=12,c=i.getUint32(j+4,!1),j+=8,d=0===b?i.getUint32(j,!1):utils.Math.to64BitNumber(i.getUint32(j+4,!1),i.getUint32(j,!1)),Q.when({earliestPresentationTime:d,timescale:c})},c=function(b){var c,d,e,f=Q.defer(),g=new XMLHttpRequest,h=!1;return c=b,g.onloadend=function(){h||(d="Error loading fragment: "+c,f.reject(d))},g.onload=function(){h=!0,e=a(g.response),f.resolve(e)},g.onerror=function(){d="Error loading fragment: "+c,f.reject(d)},g.responseType="arraybuffer",g.open("GET",c),g.send(null),f.promise};return{debug:void 0,loadFragment:c,parseTFDT:a,parseSIDX:b}},Dash.dependencies.FragmentExtensions.prototype={constructor:Dash.dependencies.FragmentExtensions},Dash.vo.Segment=function(){"use strict";this.indexRange=null,this.index=null,this.mediaRange=null,this.media=null,this.duration=0/0,this.startTime=0/0,this.timescale=0/0},Dash.vo.Segment.prototype={constructor:Dash.vo.Segment},MediaPlayer.dependencies.AbrController=function(){"use strict";var a=!0,b={},c=function(a){var c;return b.hasOwnProperty(a)||(b[a]=0),c=b[a]},d=function(a,c){b[a]=c};return{debug:void 0,abrRulesCollection:void 0,manifestExt:void 0,metricsModel:void 0,getAutoSwitchBitrate:function(){return a},setAutoSwitchBitrate:function(b){a=b},getMetricsFor:function(a){var b=Q.defer(),c=this;return c.manifestExt.getIsVideo(a).then(function(d){d?b.resolve(c.metricsModel.getMetricsFor("video")):c.manifestExt.getIsAudio(a).then(function(a){a?b.resolve(c.metricsModel.getMetricsFor("audio")):b.resolve(c.metricsModel.getMetricsFor("stream"))})}),b.promise},getPlaybackQuality:function(b,e){var f,g,h,i,j,k=this,l=Q.defer(),m=999,n=[];return j=c(b),k.debug.log("ABR enabled? ("+a+")"),a?(k.debug.log("Check ABR rules."),k.getMetricsFor(e).then(function(a){k.abrRulesCollection.getRules().then(function(c){for(f=0,g=c.length;g>f;f+=1)n.push(c[f].checkIndex(j,a,e));Q.all(n).then(function(a){for(k.debug.log(a),i={},i[MediaPlayer.rules.SwitchRequest.prototype.STRONG]=999,i[MediaPlayer.rules.SwitchRequest.prototype.WEAK]=999,i[MediaPlayer.rules.SwitchRequest.prototype.DEFAULT]=999,f=0,g=a.length;g>f;f+=1)h=a[f],h.quality!==MediaPlayer.rules.SwitchRequest.prototype.NO_CHANGE&&(i[h.priority]=Math.min(i[h.priority],h.quality));999!==i[MediaPlayer.rules.SwitchRequest.prototype.WEAK]&&(m=i[MediaPlayer.rules.SwitchRequest.prototype.WEAK]),999!==i[MediaPlayer.rules.SwitchRequest.prototype.DEFAULT]&&(m=i[MediaPlayer.rules.SwitchRequest.prototype.DEFAULT]),999!==i[MediaPlayer.rules.SwitchRequest.prototype.STRONG]&&(m=i[MediaPlayer.rules.SwitchRequest.prototype.STRONG]),999!==m&&void 0!==m&&(j=m),k.manifestExt.getRepresentationCount(e).then(function(a){0>j&&(j=0),j>=a&&(j=a-1),d(b,j),k.debug.log("New quality of "+j),l.resolve(j)})})})})):(k.debug.log("Unchanged quality of "+j),l.resolve(j)),l.promise},setPlaybackQuality:function(a,b){var e=c(a);b!==e&&d(a,b)},getQualityFor:function(a){return c(a)}}},MediaPlayer.dependencies.AbrController.prototype={constructor:MediaPlayer.dependencies.AbrController},MediaPlayer.dependencies.BufferController=function(){"use strict";var a,b,c,d,e,f=1e3,g=.5,h="WAITING",i="READY",j="VALIDATING",k="LOADING",l=h,m=!1,n=!1,o=!1,p=!0,q=!1,r=-1,s=!1,t=!0,u=-1,v=null,w=null,x=!1,y=-1,z=!1,A=!1,B=null,C=[],D=null,E=null,F=!0,G=function(a){var c=this;c.debug.log("BufferController "+b+" setState to:"+a),l=a},H=function(a,b){var c=0,d=null;F===!1&&(d=E.start,c=a.getTime()-d.getTime(),E.duration=c,E.stopreason=b,F=!0)},I=function(){var a=this.videoModel.getIsLive();return A=!0,Q.when(a)},J=function(){if(m&&n){var a=this;I.call(this).then(function(c){z=c,a.debug.log("BufferController begin "+b+" validation with interval: "+f),G.call(a,i),clearInterval(v),v=setInterval(w.bind(a),f,a)})}},K=function(){var a;null===v&&(q===!1&&(a=new Date,H(a,MediaPlayer.vo.metrics.PlayList.Trace.USER_REQUEST_STOP_REASON),D=this.metricsModel.addPlayList(b,a,0,MediaPlayer.vo.metrics.PlayList.INITIAL_PLAY_START_REASON)),this.debug.log("BufferController "+b+" start."),n=!0,o=!0,J.call(this))},L=function(a){var c;this.debug.log("BufferController "+b+" seek: "+a),q=!0,r=a,-1!==y&&(r-=y),c=new Date,H(c,MediaPlayer.vo.metrics.PlayList.Trace.USER_REQUEST_STOP_REASON),D=this.metricsModel.addPlayList(b,c,r,MediaPlayer.vo.metrics.PlayList.SEEK_START_REASON),K.call(this)},M=function(){this.debug.log("BufferController "+b+" stop."),G.call(this,h),clearInterval(v),v=null,n=!1,o=!1,H(new Date,MediaPlayer.vo.metrics.PlayList.Trace.USER_REQUEST_STOP_REASON)},N=function(a,b){var c=null;return b&&b.Representation_asArray&&b.Representation_asArray.length>0&&(c=b.Representation_asArray[a]),c},O=function(){var a=this;l===k&&(x&&!o&&(x=!1,this.videoModel.stallStream(b,x)),G.call(a,i))},P=function(a,c){var e=this;e.debug.log(b+" Bytes finished loading: "+a.url),e.fragmentController.process(c.data).then(function(a){if(null!==a){var c=N(u,e.getData()),f=e.videoModel.getCurrentTime(),g=new Date;e.debug.log("Push ("+b+") bytes: "+a.byteLength),F===!0&&l!==h&&-1!==u&&(F=!1,E=e.metricsModel.appendPlayListTrace(D,c.id,null,g,f,null,1,null)),Q.when(B||!0).then(function(){B=e.sourceBufferExt.append(d,a,e.videoModel),B.then(function(){if(e.debug.log("Append "+b+" complete: "+d.buffered.length),d.buffered.length>0){var a,c,f=d.buffered;for(e.debug.log("Number of buffered "+b+" ranges: "+f.length),a=0,c=f.length;c>a;a+=1)e.debug.log("Buffered "+b+" Range: "+f.start(a)+" - "+f.end(a))}O.call(e)})})}else e.debug.log("No "+b+" bytes to push."),O.call(e)})},R=function(a){for(var c=this,d=C.length-1;d>=0;--d)if(C[d].startTime===a.startTime){C[d].url===a.url&&C.splice(d,1);break}l===k&&G.call(c,i),this.errHandler.downloadError("Error loading "+b+" fragment: "+a.url)},S=function(){M.call(this)},T=function(a,d){var e=null;return p&&(this.debug.log("Marking a special seek for initial "+b+" playback."),q||(q=!0,r=0),p=!1),e=a?this.indexHandler.getInitRequest(d,c):Q.when(null)},U=function(e){var f,g=this;if(t&&!q)g.debug.log("Data changed - loading the "+b+" fragment for time: "+a),f=g.indexHandler.getSegmentRequestForTime(a,e,c);else{var h=Q.defer(),i=g.videoModel.getCurrentTime();f=h.promise,q=!1,g.sourceBufferExt.getBufferRange(d,i).then(function(a){null!==a&&(i=a.end),g.debug.log("Loading the "+b+" fragment for time: "+i),g.indexHandler.getSegmentRequestForTime(i,e,c).then(function(a){h.resolve(a)})})}return t=!1,f},V=function(a){var d=this;if(null!==a){switch(a.action){case"complete":d.debug.log(b+" Stream is complete."),H(new Date,MediaPlayer.vo.metrics.PlayList.Trace.END_OF_CONTENT_STOP_REASON),S.call(d);break;case"download":for(var e=C.length-1;e>=0;--e)if(C[e].startTime===a.startTime){if(d.debug.log(b+" Fragment already loaded for time: "+a.startTime),C[e].url===a.url)return d.debug.log(b+" Fragment url already loaded: "+a.url),d.indexHandler.getNextSegmentRequest(u,c).then(V.bind(d)),void 0;C.splice(e,1);break}C.push(a),d.debug.log("Loading an "+b+" fragment: "+a.url),G.call(d,k),d.fragmentLoader.load(a).then(P.bind(d,a),R.bind(d,a));break;default:d.debug.log("Unknown request action.")}a=null}l===j&&G.call(d,i)},W=function(a){o&&(e>a?x||(this.debug.log("Waiting for more "+b+" buffer before starting playback."),x=!0,this.videoModel.stallStream(b,x)):(this.debug.log("Got enough "+b+" buffer to start."),o=!1,x=!1,this.videoModel.stallStream(b,x)))},X=function(){var a=-1;return a=this.videoModel.getCurrentTime(),this.debug.log("Working time is video time: "+a),a},Y=function(){var a,e=this,h=null,m=new Date,n=e.videoModel.getCurrentTime(),p=X.call(e);e.debug.log("BufferController.validate() "+b+" | state: "+l),e.debug.log(b+" Playback rate: "+e.videoModel.getElement().playbackRate),e.debug.log(b+" Working time: "+p),e.debug.log(b+" Video time: "+n),e.sourceBufferExt.getBufferLength(d,p).then(function(d){e.debug.log("Current "+b+" buffer length: "+d),e.metricsModel.addBufferLevel(b,new Date,d),W.call(e,d),l===k&&g>d?x||(e.debug.log("Stalling "+b+" Buffer: "+b),H(new Date,MediaPlayer.vo.metrics.PlayList.Trace.REBUFFERING_REASON),x=!0,o=!0,e.videoModel.stallStream(b,x)):l===i&&(G.call(e,j),e.bufferExt.shouldBufferMore(d,f/1e3).then(function(d){d?e.abrController.getPlaybackQuality(b,c).then(function(c){if(e.debug.log(b+" Playback quality: "+c),e.debug.log("Populate "+b+" buffers."),void 0!==c&&(a=c),s=c!==u,s===!0){if(h=N(a,e.getData()),null===h||void 0===h)throw"Unexpected error!";H(new Date,MediaPlayer.vo.metrics.PlayList.Trace.REPRESENTATION_SWITCH_STOP_REASON),e.metricsModel.addRepresentationSwitch(b,m,n,h.id)}return e.debug.log(s?b+" Quality changed to: "+c:"Quality didn't change."),T.call(e,s,c)}).then(function(c){null!==c?(e.debug.log("Loading "+b+" initialization: "+c.url),e.debug.log(c),G.call(e,k),e.fragmentLoader.load(c).then(P.bind(e,c),R.bind(e,c)),u=a):U.call(e,a).then(V.bind(e))}):(q=!1,l===j&&G.call(e,i))}))})};return w=function(){Y.call(this)},{videoModel:void 0,metricsModel:void 0,manifestExt:void 0,manifestModel:void 0,bufferExt:void 0,sourceBufferExt:void 0,fragmentController:void 0,abrController:void 0,fragmentExt:void 0,fragmentLoader:void 0,indexHandler:void 0,debug:void 0,system:void 0,errHandler:void 0,setup:function(){var a=this,c=a.videoModel.getIsLive();a.indexHandler.setIsLive(c),a.manifestExt.getDuration(a.manifestModel.getValue(),c).then(function(b){a.indexHandler.setDuration(b)}),a.indexHandler.setType(b),m=!0,J.call(this)},getType:function(){return b},setType:function(a){b=a,void 0!==this.indexHandler&&this.indexHandler.setType(a)},getAutoSwitchBitrate:function(){var a=this;return a.abrController.getAutoSwitchBitrate()},setAutoSwitchBitrate:function(a){var b=this;b.abrController.setAutoSwitchBitrate(a)},getData:function(){return c},setData:function(d){var e=this;null!==c&&void 0!==c?e.abrController.getPlaybackQuality(b,c).then(function(b){e.indexHandler.getCurrentTime(b,c).then(function(b){t=!0,a=b,c=d})}):c=d},getBuffer:function(){return d},setBuffer:function(a){d=a},getMinBufferTime:function(){return e},setMinBufferTime:function(a){var c=this;e=a,f=1e3*e/4,f=Math.max(f,1e3),null!==v&&(c.debug.log("Changing "+b+" validate interval: "+f),clearInterval(v),v=setInterval(w.bind(this),f,this))},clearMetrics:function(){var a=this;null!==b&&""!==b&&a.metricsModel.clearCurrentMetricsForType(b)},start:K,seek:L,stop:M}},MediaPlayer.dependencies.BufferController.prototype={constructor:MediaPlayer.dependencies.BufferController},MediaPlayer.dependencies.BufferExtensions=function(){"use strict";var a;return{decideBufferLength:function(b){return a=4,a=isNaN(b)||0>=b?4:b,Q.when(a)},shouldBufferMore:function(b,c){var d=1.5*a>b-c;return Q.when(d)}}},MediaPlayer.dependencies.BufferExtensions.prototype={constructor:MediaPlayer.dependencies.BufferExtensions},MediaPlayer.utils.Capabilities=function(){"use strict"},MediaPlayer.utils.Capabilities.prototype={constructor:MediaPlayer.utils.Capabilities,supportsMediaSource:function(){"use strict";var a=null!==window.WebKitMediaSource&&void 0!==window.WebKitMediaSource,b=null!==window.MediaSource&&void 0!==window.MediaSource;return a||b},supportsCodec:function(a,b){"use strict";if(!(a instanceof HTMLVideoElement))throw"element must be of type HTMLVideoElement.";var c=a.canPlayType(b);return"probably"===c}},$.expr[":"].contains=$.expr.createPseudo(function(a){return function(b){return $(b).text().toUpperCase().indexOf(a.toUpperCase())>=0}}),MediaPlayer.utils.Debug=function(){"use strict";var a=null,b=!1,c="",d=function(){if(null!==a){var b,d=a.children();""===c||void 0===c||null===c?d.show():(b=d.filter(":contains("+c+")"),d.not(b).hide(),b.show())}},e=function(){var b=a.children()[0];""===c||void 0===c||null===c?$(b).show():-1===$(b).text().toUpperCase().indexOf(c.toUpperCase())&&$(b).hide()};return{init:function(b){a=$(b)},clear:function(){a.empty()},getFilter:function(){return c},setFilter:function(a){a!==c&&(c=a,d())},getLogToHtmlConsole:function(){return b},setLogToHtmlConsole:function(a){b=a},log:function(c){if(console.log(c),null!==a&&b){var d="<dt>"+c+"</dt>";a.prepend(d),e()}}}},MediaPlayer.dependencies.ErrorHandler=function(){"use strict";return{downloadError:function(a){var b="<span>File loading error. This is most likely caused by the Cross Origin Resource Sharing (CORS) headers not being present in the response from the server which is hosting the file. Please check your server implementation to ensure that CORS headers are in place, as the JavaScript will not be able to request the manifest or segments without them.</span>",c="<div id='message' class='message' style='display: none'><p><span style='text-align: center; width: 100%; font-weight: bold;'>"+a+"</span><br/><br/>"+b+"</p><a href='#' class='close-notify'>X</a></div>";$("body").append(c),$("#message").fadeIn("slow"),$("#message a.close-notify").click(function(){return $("#message").fadeOut("slow"),!1})},mediaSourceError:function(a){var b="<span>MediaSource has encountered an error.</span>",c="<div id='message' class='message' style='display: none'><p><span style='text-align: center; width: 100%; font-weight: bold;'>"+a+"</span><br/><br/>"+b+"</p><a href='#' class='close-notify'>X</a></div>";$("body").append(c),$("#message").fadeIn("slow"),$("#message a.close-notify").click(function(){return $("#message").fadeOut("slow"),!1})}}},MediaPlayer.dependencies.ErrorHandler.prototype={constructor:MediaPlayer.dependencies.ErrorHandler},MediaPlayer.dependencies.FragmentController=function(){"use strict"},MediaPlayer.dependencies.FragmentController.prototype={constructor:MediaPlayer.dependencies.FragmentController,process:function(a){"use strict";var b=null;return null!==a&&void 0!==a&&a.byteLength>0&&(b=new Uint8Array(a)),Q.when(b)}},MediaPlayer.dependencies.FragmentLoader=function(){"use strict";var a=[],b=null,c=!1,d=function(){var e=new XMLHttpRequest,f=null,g=!0,h=!1,i=this;a.length>0?(b=a.shift(),b.requestStartDate=new Date,b.firstByteDate=b.requestStartDate,c=!0,e.open("GET",b.url,!0),e.responseType="arraybuffer",b.range&&e.setRequestHeader("Range","bytes="+b.range),e.onloadend=function(){h||b.deferred.reject("Error loading fragment.")},e.onprogress=function(a){g&&(g=!1,(!a.lengthComputable||a.lengthComputable&&a.total!=a.loaded)&&(b.firstByteDate=new Date))},e.onload=function(){h=!0,b.requestEndDate=new Date;var a=b.requestEndDate,c=e.response,g=b.firstByteDate.getTime()-b.requestStartDate.getTime(),j=b.requestEndDate.getTime()-b.firstByteDate.getTime(),k=b.requestEndDate.getTime()-b.requestStartDate.getTime();i.debug.log("segment loaded: ("+e.status+", "+g+"ms, "+j+"ms, "+k+"ms) "+b.url),f=i.metricsModel.addHttpRequest(b.streamType,null,b.type,b.url,null,b.range,b.requestStartDate,b.firstByteDate,b.requestEndDate,e.status,null,b.duration),i.metricsModel.appendHttpTrace(f,a,(new Date).getTime()-a.getTime(),[c.byteLength]),b.deferred.resolve({data:c,request:b}),b.deferred=null,b=null,e=null,d.call(i)},e.onerror=function(){b.requestEndDate=new Date;var a=b.firstByteDate.getTime()-b.requestStartDate.getTime(),c=b.requestEndDate.getTime()-b.firstByteDate.getTime(),d=b.requestEndDate.getTime()-b.requestStartDate.getTime();i.debug.log("segment loaded: ("+e.status+", "+a+"ms, "+c+"ms, "+d+"ms) "+b.url),f=i.metricsModel.addHttpRequest(b.streamType,null,b.type,b.url,null,b.range,b.requestStartDate,b.firstByteDate,b.requestEndDate,e.status,null,b.duration),b.deferred.reject("Error loading fragment.")},e.send()):c=!1},e=function(b){var e=Q.defer();return b.deferred=e,a.push(b),c||d.call(this),e.promise};return{metricsModel:void 0,debug:void 0,getLoading:function(){return c},load:function(a){var b=null;if(a)return b=e.call(this,a)}}},MediaPlayer.dependencies.FragmentLoader.prototype={constructor:MediaPlayer.dependencies.FragmentLoader},MediaPlayer.dependencies.ManifestLoader=function(){"use strict";var a=function(a){var b=null;return-1!==a.indexOf("/")&&(b=a.substring(0,a.lastIndexOf("/")+1)),b},b=function(b){var c=a(b),d=Q.defer(),e=new XMLHttpRequest,f=new Date,g=!1,h=this;return this.debug.log("Start loading manifest: "+b),e.open("GET",b,!0),e.onloadend=function(){g||d.reject("Error loading manifest.")},e.onload=function(){g=!0,h.metricsModel.addHttpRequest("stream",null,"MPD",b,null,null,f,new Date,e.status,null,null),h.parser.parse(e.responseText,c).then(function(a){a.mpdUrl=b,d.resolve(a)})},e.onerror=function(){h.metricsModel.addHttpRequest("stream",null,"MPD",b,null,null,f,new Date,e.status,null,null),d.reject("Error loading manifest.")},e.send(),d.promise};return{debug:void 0,parser:void 0,metricsModel:void 0,load:b}},MediaPlayer.dependencies.ManifestLoader.prototype={constructor:MediaPlayer.dependencies.ManifestLoader},MediaPlayer.models.ManifestModel=function(){"use strict";var a;return{getValue:function(){return a},setValue:function(b){a=b}}},MediaPlayer.models.ManifestModel.prototype={constructor:MediaPlayer.models.ManifestModel},MediaPlayer.dependencies.ManifestUpdater=function(){"use strict";var a=0/0,b=null,c=null,d=function(){null!==b&&(clearInterval(b),b=null)},e=function(){d.call(this),isNaN(a)||(this.debug.log("Refresh manifest in "+a+" seconds."),b=setInterval(c.bind(this),1e3*a,this))},f=function(){var b=this,c=b.manifestModel.getValue();void 0!==c&&null!==c&&b.manifestExt.getRefreshDelay(c).then(function(c){a=c,e.call(b)})};return c=function(){var a=this,b=a.manifestModel.getValue(),c=b.mpdUrl;b.hasOwnProperty("Location")&&(c=b.Location),a.debug.log("Refresh manifest @ "+c),a.manifestLoader.load(c).then(function(b){a.manifestModel.setValue(b),a.debug.log("Manifest has been refreshed."),a.debug.log(b),f.call(a),a.system.notify("manifestUpdated")})},{debug:void 0,system:void 0,manifestModel:void 0,manifestExt:void 0,manifestLoader:void 0,setup:function(){f.call(this)},init:function(){f.call(this)}}},MediaPlayer.dependencies.ManifestUpdater.prototype={constructor:MediaPlayer.dependencies.ManifestUpdater},MediaPlayer.dependencies.MediaSourceExtensions=function(){"use strict"},MediaPlayer.dependencies.MediaSourceExtensions.prototype={constructor:MediaPlayer.dependencies.MediaSourceExtensions,createMediaSource:function(){"use strict";var a="WebKitMediaSource"in window,b="MediaSource"in window;return b?Q.when(new MediaSource):a?Q.when(new WebKitMediaSource):null},attachMediaSource:function(a,b){"use strict";return b.setSource(window.URL.createObjectURL(a)),Q.when(!0)},setDuration:function(a,b){"use strict";return a.duration=b,Q.when(a.duration)}},MediaPlayer.models.MetricsModel=function(){"use strict";return{system:void 0,streamMetrics:{},clearCurrentMetricsForType:function(a){delete this.streamMetrics[a]},clearAllCurrentMetrics:function(){this.streamMetrics={}},getReadOnlyMetricsFor:function(a){return this.streamMetrics.hasOwnProperty(a)?this.streamMetrics[a]:null},getMetricsFor:function(a){var b;return this.streamMetrics.hasOwnProperty(a)?b=this.streamMetrics[a]:(b=this.system.getObject("metrics"),this.streamMetrics[a]=b),b},addTcpConnection:function(a,b,c,d,e,f){var g=new MediaPlayer.vo.metrics.TCPConnection;return g.tcpid=b,g.dest=c,g.topen=d,g.tclose=e,g.tconnect=f,this.getMetricsFor(a).TcpList.push(g),g},addHttpRequest:function(a,b,c,d,e,f,g,h,i,j,k,l){var m=new MediaPlayer.vo.metrics.HTTPRequest;return m.tcpid=b,m.type=c,m.url=d,m.actualurl=e,m.range=f,m.trequest=g,m.tresponse=h,m.tfinish=i,m.responsecode=j,m.interval=k,m.mediaduration=l,this.getMetricsFor(a).HttpList.push(m),m},appendHttpTrace:function(a,b,c,d){var e=new MediaPlayer.vo.metrics.HTTPRequest.Trace;return e.s=b,e.d=c,e.b=d,a.trace.push(e),e},addRepresentationSwitch:function(a,b,c,d,e){var f=new MediaPlayer.vo.metrics.RepresentationSwitch;return f.t=b,f.mt=c,f.to=d,f.lto=e,this.getMetricsFor(a).RepSwitchList.push(f),f},addBufferLevel:function(a,b,c){var d=new MediaPlayer.vo.metrics.BufferLevel;return d.t=b,d.level=c,this.getMetricsFor(a).BufferLevel.push(d),d},addPlayList:function(a,b,c,d){var e=new MediaPlayer.vo.metrics.PlayList;return e.start=b,e.mstart=c,e.starttype=d,this.getMetricsFor(a).PlayList.push(e),e},appendPlayListTrace:function(a,b,c,d,e,f,g,h){var i=new MediaPlayer.vo.metrics.PlayList.Trace;return i.representationid=b,i.subreplevel=c,i.start=d,i.mstart=e,i.duration=f,i.playbackspeed=g,i.stopreason=h,a.trace.push(i),i}}},MediaPlayer.models.MetricsModel.prototype={constructor:MediaPlayer.models.MetricsModel},MediaPlayer.dependencies.SourceBufferExtensions=function(){"use strict"},MediaPlayer.dependencies.SourceBufferExtensions.prototype={constructor:MediaPlayer.dependencies.SourceBufferExtensions,createSourceBuffer:function(a,b){"use strict";return Q.when(a.addSourceBuffer(b))},removeSourceBuffer:function(a,b){"use strict";return Q.when(a.removeSourceBuffer(b))},getBufferRange:function(a,b,c){"use strict";var d,e,f=null,g=-1,h=-1,i=c||.1;if(f=a.buffered,null!==f){for(e=0,d=f.length;d>e;e+=1)if(-1!==h){if(!(f.start(e)-f.end(h)<=i))break;h=e}else b>=f.start(e)&&b<f.end(e)&&(g=e,h=e);if(-1!==g)return Q.when({start:f.start(g),end:f.end(h)})}return Q.when(null)},getBufferLength:function(a,b,c){"use strict";var d=this,e=Q.defer();return d.getBufferRange(a,b,c).then(function(a){null===a?e.resolve(0):e.resolve(a.end-b)}),e.promise},append:function(a,b){"use strict";var c=Q.defer(),d=function(){a.removeEventListener("updateend",d,!1),c.resolve(!0)};try{a.addEventListener("updateend",d,!1)}catch(e){c.resolve(!0)}try{"append"in a?a.append(b):"appendBuffer"in a&&a.appendBuffer(b)}catch(e){return Q.when(!1)}return c.promise},abort:function(a){"use strict";return Q.when(a.abort())}},MediaPlayer.dependencies.Stream=function(){"use strict";var a,b,c,d,e,f,g,h,i,j=null,k=-1,l=null,m=-1,n=!0,o=!1,p=!1,q=!1,r=null,s=!1,t="webkit-org.w3.clearkey",u=function(){this.debug.log("Attempting play..."),o&&(this.debug.log("Do play."),this.videoModel.play())},v=function(){this.debug.log("Do pause."),this.videoModel.pause()},w=function(a){this.debug.log("Attempting seek..."),o&&(this.debug.log("Do seek: "+a),this.system.notify("setCurrentTime"),this.videoModel.setCurrentTime(a),j&&j.seek(a),l&&l.seek(a))},x=function(a){this.debug.log("DRM: Key required."),this.debug.log("DRM: Generating key request..."),this.videoModel.generateKeyRequest(t,a.initData)},y=function(a){this.debug.log("DRM: Got a key message..."),this.debug.log("DRM: Key system = "+a.keySystem),a.keySystem!==t&&this.debug.log("DRM: Key type not supported!")},z=function(){this.debug.log("DRM: Key added.")},A=function(){var a=Q.defer(),c=this,d=function(a){var b=c.videoModel.getElement().error,d=null!==b&&void 0!==b?b.code:-1,e="";if(-1!==d){switch(d){case 1:e="MEDIA_ERR_ABORTED";break;case 2:e="MEDIA_ERR_NETWORK";break;case 3:e="MEDIA_ERR_DECODE";break;case 4:e="MEDIA_ERR_SRC_NOT_SUPPORTED";break;case 5:e="MEDIA_ERR_ENCRYPTED"}s=!0,v.call(c),c.debug.log("MediaSource Close."),c.debug.log(a),c.debug.log("Video Element Error:"),c.debug.log(c.videoModel.getElement().error),c.errHandler.mediaSourceError(e)}},e=function(d){c.debug.log("MediaSource is open!"),c.debug.log(d),b.removeEventListener("sourceopen",e),b.removeEventListener("webkitsourceopen",e),a.resolve(b)};return c.debug.log("MediaSource should be closed. ("+b.readyState+")"),b.addEventListener("sourceclose",d,!1),b.addEventListener("webkitsourceclose",d,!1),b.addEventListener("sourceopen",e,!1),b.addEventListener("webkitsourceopen",e,!1),b.addEventListener("webkitneedkey",x.bind(c),!1),b.addEventListener("webkitkeymessage",y.bind(c),!1),b.addEventListener("webkitkeyadded",z.bind(c),!1),c.mediaSourceExt.attachMediaSource(b,c.videoModel),c.debug.log("MediaSource attached to video. Waiting on open..."),a.promise},B=function(){j.clearMetrics(),l.clearMetrics()},C=function(){var a,c,d=this;j.stop(),l.stop(),B.call(this),s||(a=j.getBuffer(),d.sourceBufferExt.abort(a),d.sourceBufferExt.removeSourceBuffer(b,a),c=l.getBuffer(),d.sourceBufferExt.abort(c),d.sourceBufferExt.removeSourceBuffer(b,c)),j=null,l=null,d.videoModel.setSource(null)},D=function(a,b,c){if(a&&b)if(null===j&&null===l){var d="No streams to play.";alert(d),this.debug.log(d),c.reject(d)}else this.debug.log("MediaSource initialized!"),c.resolve(!0)},E=function(){this.debug.log("Getting MediaSource ready...");var a,c=Q.defer(),d=!1,e=!1,f=this,g=f.manifestModel.getValue(),h=f.videoModel.getIsLive();return f.debug.log("Gathering information for buffers. (1)"),f.manifestExt.getDuration(g,h).then(function(){f.debug.log("Gathering information for buffers. (2)"),f.bufferExt.decideBufferLength(g.minBufferTime).then(function(b){return f.debug.log("Gathering information for buffers. (3)"),f.debug.log("Buffer time: "+b),a=b,f.manifestExt.getVideoData(g)}).then(function(h){return null!==h?(f.debug.log("Create video buffer."),f.manifestExt.getDataIndex(h,g).then(function(a){k=a,f.debug.log("Save video track: "+k)}),f.manifestExt.getCodec(h).then(function(a){var c;return f.debug.log("Video codec: "+a),f.capabilities.supportsCodec(f.videoModel.getElement(),a)?c=f.sourceBufferExt.createSourceBuffer(b,a):(f.debug.log("Codec ("+a+") is not supported."),alert("Codec ("+a+") is not supported."),c=Q.when(null)),c}).then(function(b){null===b?f.debug.log("No buffer was created, skipping video stream."):(j=f.system.getObject("bufferController"),j.setType("video"),j.setData(h),j.setBuffer(b),j.setMinBufferTime(a),f.debug.log("Video is ready!")),d=!0,D.call(f,d,e,c)},function(){alert("Error creating source buffer."),d=!0,D.call(f,d,e,c)})):(f.debug.log("No video data."),d=!0,D.call(f,d,e,c)),f.manifestExt.getAudioDatas(g)}).then(function(h){null!==h&&h.length>0?(f.debug.log("Have audio streams: "+h.length),f.manifestExt.getPrimaryAudioData(g).then(function(h){f.manifestExt.getDataIndex(h,g).then(function(a){m=a,f.debug.log("Save audio track: "+m)}),f.manifestExt.getCodec(h).then(function(a){var c;return f.debug.log("Audio codec: "+a),f.capabilities.supportsCodec(f.videoModel.getElement(),a)?c=f.sourceBufferExt.createSourceBuffer(b,a):(f.debug.log("Codec ("+a+") is not supported."),alert("Codec ("+a+") is not supported."),c=Q.when(null)),c}).then(function(b){null===b?f.debug.log("No buffer was created, skipping audio stream."):(l=f.system.getObject("bufferController"),l.setType("audio"),l.setData(h),l.setBuffer(b),l.setMinBufferTime(a),f.debug.log("Audio is ready!")),e=!0,D.call(f,d,e,c)},function(){alert("Error creating source buffer."),e=!0,D.call(f,d,e,c)})})):(f.debug.log("No audio streams."),e=!0,D.call(f,d,e,c))})}),c.promise},F=function(){var a=this,c=Q.defer(),d=a.videoModel.getIsLive();return a.debug.log("Getting ready for playback..."),a.manifestExt.getDuration(a.manifestModel.getValue(),d).then(function(c){return a.debug.log("Setting duration: "+c),a.mediaSourceExt.setDuration(b,c)}).then(function(){a.debug.log("Duration successfully set."),o=!0,c.resolve(!0)}),c.promise},G=function(){this.debug.log("Got loadmetadata event."),r.resolve(null)},H=function(){this.debug.log("Got play event."),o&&(this.debug.log("Starting playback."),j&&j.start(),l&&l.start())},I=function(){this.debug.log("Got pause event."),j&&j.stop(),l&&l.stop()},J=function(){this.debug.log("Got seeking event."),j&&j.seek(this.videoModel.getCurrentTime()),l&&l.seek(this.videoModel.getCurrentTime())},K=function(){this.debug.log("Seek complete."),this.videoModel.listen("seeking",g),this.videoModel.unlisten("seeked",h)},L=function(){},M=function(){if(p&&q){var d=this,e=c,f=d.videoModel.getIsLive();d.debug.log("Stream start loading."),d.manifestLoader.load(e).then(function(b){return a=b,d.manifestModel.setValue(a),d.debug.log("Manifest has loaded."),d.debug.log(d.manifestModel.getValue()),d.manifestUpdater.init(),d.mediaSourceExt.createMediaSource()}).then(function(a){return b=a,d.debug.log("MediaSource created."),A.call(d)}).then(function(){return d.debug.log("MediaSource set up."),E.call(d)}).then(function(){return d.debug.log("Start initializing playback."),F.call(d)}).then(function(){return d.debug.log("Playback initialized!"),u.call(d),r.promise}).then(function(){d.debug.log("element loaded!"),f?d.manifestExt.getLiveEdge(d.manifestModel.getValue()).then(function(a){d.debug.log("Got live content. Starting playback at offset: "+a),w.call(d,a)}):d.manifestExt.getPresentationOffset(d.manifestModel.getValue()).then(function(a){d.debug.log("Got VOD content. Starting playback at offset: "+a),w.call(d,a)})})}},N=function(){this.debug.log("Current time has changed, block programmatic seek."),this.videoModel.unlisten("seeking",g),this.videoModel.listen("seeked",h)},O=function(){var a,b,c=this,d=c.manifestModel.getValue();c.debug.log("Manifest updated... set new data on buffers."),j&&(a=j.getData(),a.hasOwnProperty("id")?c.manifestExt.getDataForId(a.id,d).then(function(a){j.setData(a)}):c.manifestExt.getDataForIndex(k,d).then(function(a){j.setData(a)})),l&&(b=l.getData(),b.hasOwnProperty("id")?c.manifestExt.getDataForId(b.id,d).then(function(a){l.setData(a)}):c.manifestExt.getDataForIndex(m,d).then(function(a){l.setData(a)}))};return{system:void 0,videoModel:void 0,manifestLoader:void 0,manifestUpdater:void 0,manifestModel:void 0,mediaSourceExt:void 0,sourceBufferExt:void 0,bufferExt:void 0,manifestExt:void 0,fragmentController:void 0,abrController:void 0,fragmentExt:void 0,capabilities:void 0,debug:void 0,metricsExt:void 0,errHandler:void 0,setup:function(){this.system.mapHandler("manifestUpdated",void 0,O.bind(this)),this.system.mapHandler("setCurrentTime",void 0,N.bind(this)),r=Q.defer(),e=H.bind(this),f=I.bind(this),g=J.bind(this),h=K.bind(this),i=L.bind(this),d=G.bind(this),this.videoModel.listen("play",e),this.videoModel.listen("pause",f),this.videoModel.listen("seeking",g),this.videoModel.listen("timeupdate",i),this.videoModel.listen("loadedmetadata",d),p=!0,M.call(this)},getManifestExt:function(){var a=this;return a.manifestExt},setAutoPlay:function(a){n=a},getAutoPlay:function(){return n},load:function(a){c=a,q=!0,M.call(this)},reset:function(){v.call(this),C.call(this)},play:u,seek:w,pause:v}},MediaPlayer.dependencies.Stream.prototype={constructor:MediaPlayer.dependencies.Stream},MediaPlayer.models.VideoModel=function(){"use strict";var a,b=!1,c=[],d=function(){return c.length>0},e=function(b){null!==b&&c[b]!==!0&&(c.push(b),c[b]=!0,a.playbackRate=0)},f=function(b){if(null!==b){c[b]=!1;var e=c.indexOf(b);-1!==e&&c.splice(e,1),d()===!1&&(a.playbackRate=1)}},g=function(a,b){b?e(a):f(a)};return{system:void 0,setup:function(){},play:function(){a.play()},pause:function(){a.pause()},isPaused:function(){return a.paused},getPlaybackRate:function(){return a.playbackRate},setPlaybackRate:function(b){a.playbackRate=b},getCurrentTime:function(){return a.currentTime},setCurrentTime:function(b){a.currentTime=b},listen:function(b,c){a.addEventListener(b,c,!1)},unlisten:function(b,c){a.removeEventListener(b,c,!1)},getElement:function(){return a},setElement:function(b){a=b},setSource:function(b){a.src=b},getIsLive:function(){return b},setIsLive:function(a){b=a},addKey:function(b,c,d,e){a.webkitAddKey(b,c,d,e)
},generateKeyRequest:function(b,c){a.webkitGenerateKeyRequest(b,c)},stallStream:g,isStalled:d}},MediaPlayer.models.VideoModel.prototype={constructor:MediaPlayer.models.VideoModel},MediaPlayer.dependencies.VideoModelExtensions=function(){"use strict";return{getDroppedFrames:function(a){var b=null!==a.webkitDroppedFrameCount,c=-1;return b&&(c=a.webkitDroppedFrameCount),c}}},MediaPlayer.dependencies.VideoModelExtensions.prototype={constructor:MediaPlayer.dependencies.VideoModelExtensions},MediaPlayer.rules.BaseRulesCollection=function(){"use strict";var a=[];return{downloadRatioRule:void 0,insufficientBufferRule:void 0,getRules:function(){return Q.when(a)},setup:function(){var a=this;a.getRules().then(function(b){b.push(a.downloadRatioRule),b.push(a.insufficientBufferRule)})}}},MediaPlayer.rules.BaseRulesCollection.prototype={constructor:MediaPlayer.rules.BaseRulesCollection},MediaPlayer.rules.DownloadRatioRule=function(){"use strict";var a=function(a,b){var c=this,d=Q.defer();return c.manifestExt.getBandwidth(a).then(function(a){c.manifestExt.getBandwidth(b).then(function(b){d.resolve(a/b)})}),d.promise};return{debug:void 0,manifestExt:void 0,checkIndex:function(b,c,d){var e,f,g,h,i,j,k,l,m,n,o=this,p=c.HttpList;return o.debug.log("Checking download ratio rule..."),c?null===p||void 0===p||0===p.length?(o.debug.log("No requests made for this stream yet, bailing."),Q.when(new MediaPlayer.rules.SwitchRequest)):(e=p[p.length-1],g=(e.tfinish.getTime()-e.trequest.getTime())/1e3,f=(e.tfinish.getTime()-e.tresponse.getTime())/1e3,0>=g?(o.debug.log("Don't know how long the download of the last fragment took, bailing."),Q.when(new MediaPlayer.rules.SwitchRequest)):null===e.mediaduration||void 0===e.mediaduration||e.mediaduration<=0?(o.debug.log("Don't know the duration of the last media fragment, bailing."),Q.when(new MediaPlayer.rules.SwitchRequest)):(k=Q.defer(),i=e.mediaduration/g,h=e.mediaduration/f,isNaN(h)||isNaN(i)?(o.debug.log("Total time: "+g+"s"),o.debug.log("Download time: "+f+"s"),o.debug.log("The ratios are NaN, bailing."),Q.when(new MediaPlayer.rules.SwitchRequest)):(o.debug.log("Total ratio: "+i),o.debug.log("Download ratio: "+h),h=i,o.debug.log("Download ratio: "+h),isNaN(h)?(o.debug.log("Invalid ratio, bailing."),k.resolve(new MediaPlayer.rules.SwitchRequest)):1>h?(o.debug.log("Download ratio is poor."),b>0?(o.debug.log("We are not at the lowest bitrate, so switch down."),o.manifestExt.getRepresentationFor(b-1,d).then(function(a){o.manifestExt.getBandwidth(a).then(function(a){o.manifestExt.getRepresentationFor(b,d).then(function(c){o.manifestExt.getBandwidth(c).then(function(c){j=a/c,o.debug.log("Switch ratio: "+j),j>h?(o.debug.log("Things must be going pretty bad, switch all the way down."),k.resolve(new MediaPlayer.rules.SwitchRequest(0))):(o.debug.log("Things could be better, so just switch down one index."),k.resolve(new MediaPlayer.rules.SwitchRequest(b-1)))})})})})):(o.debug.log("We are at the lowest bitrate and cannot switch down, use current."),k.resolve(new MediaPlayer.rules.SwitchRequest(b)))):(o.debug.log("Download ratio is good."),o.manifestExt.getRepresentationCount(d).then(function(c){c-=1,c>b?(o.debug.log("We are not at the highest bitrate, so switch up."),o.manifestExt.getRepresentationFor(b+1,d).then(function(e){o.manifestExt.getBandwidth(e).then(function(e){o.manifestExt.getRepresentationFor(b,d).then(function(d){o.manifestExt.getBandwidth(d).then(function(d){if(j=e/d,o.debug.log("Switch ratio: "+j),h>=j)if(h>1e3)o.debug.log("Tons of bandwidth available, go all the way up."),k.resolve(new MediaPlayer.rules.SwitchRequest(c-1));else if(h>100)o.debug.log("Just enough bandwidth available, switch up one."),k.resolve(new MediaPlayer.rules.SwitchRequest(b+1));else{for(o.debug.log("Not exactly sure where to go, so do some math."),m=-1,l=[];(m+=1)<c;)l.push(a.call(o,m,b));Q.all(l).then(function(a){for(m=0,n=a.length;n>m&&!(h<a[m]);m+=1);o.debug.log("Calculated ideal new quality index is: "+m),k.resolve(new MediaPlayer.rules.SwitchRequest(m))})}else o.debug.log("Not enough bandwidth to switch up."),k.resolve(new MediaPlayer.rules.SwitchRequest)})})})})):(o.debug.log("We are at the highest bitrate and cannot switch up, use current."),k.resolve(new MediaPlayer.rules.SwitchRequest(c)))})),k.promise))):(o.debug.log("No metrics, bailing."),Q.when(new MediaPlayer.rules.SwitchRequest))}}},MediaPlayer.rules.DownloadRatioRule.prototype={constructor:MediaPlayer.rules.DownloadRatioRule},MediaPlayer.rules.InsufficientBufferRule=function(){"use strict";var a=0,b=3;return{debug:void 0,checkIndex:function(c,d){var e,f,g=this,h=!1,i=MediaPlayer.rules.SwitchRequest.prototype.DEFAULT;return g.debug.log("Checking insufficient buffer rule..."),null===d.PlayList||void 0===d.PlayList||0===d.PlayList.length?(g.debug.log("Not enough information for rule."),Q.when(new MediaPlayer.rules.SwitchRequest)):(e=d.PlayList[d.PlayList.length-1],null===e||void 0===e||0===e.trace.length?(g.debug.log("Not enough information for rule."),Q.when(new MediaPlayer.rules.SwitchRequest)):(f=e.trace[e.trace.length-2],null===f||void 0===f||null===f.stopreason||void 0===f.stopreason?(g.debug.log("Not enough information for rule."),Q.when(new MediaPlayer.rules.SwitchRequest)):(f.stopreason===MediaPlayer.vo.metrics.PlayList.Trace.REBUFFERING_REASON&&(h=!0,a+=1,g.debug.log("Number of times the buffer has run dry: "+a)),a>b&&(i=MediaPlayer.rules.SwitchRequest.prototype.STRONG,g.debug.log("Apply STRONG to buffer rule.")),h?(g.debug.log("The buffer ran dry recently, switch down."),Q.when(new MediaPlayer.rules.SwitchRequest(c-1,i))):a>b?(g.debug.log("Too many dry buffer hits, quit switching bitrates."),Q.when(new MediaPlayer.rules.SwitchRequest(c,i))):Q.when(new MediaPlayer.rules.SwitchRequest(MediaPlayer.rules.SwitchRequest.prototype.NO_CHANGE,i)))))}}},MediaPlayer.rules.InsufficientBufferRule.prototype={constructor:MediaPlayer.rules.InsufficientBufferRule},MediaPlayer.rules.LimitSwitchesRule=function(){"use strict";var a=10,b=2e4,c=5,d=0;return{debug:void 0,checkIndex:function(e,f){if(d>0)return d-=1,Q.when(new MediaPlayer.rules.SwitchRequest(e,MediaPlayer.rules.SwitchRequest.prototype.STRONG));var g,h,i,j=this,k=!1,l=(new Date).getTime(),m=f.RepSwitchList.length;for(j.debug.log("Checking limit switches rule..."),i=m-1;i>=0;i-=1){if(g=f.RepSwitchList[i],h=l-g.t.getTime(),h>=b){j.debug.log("Reached time limit, bailing.");break}if(i>=a){j.debug.log("Found too many switches within validation time, force the stream to not change."),k=!0;break}}return k?(j.debug.log("Wait some time before allowing another switch."),d=c,Q.when(new MediaPlayer.rules.SwitchRequest(e,MediaPlayer.rules.SwitchRequest.prototype.STRONG))):Q.when(new MediaPlayer.rules.SwitchRequest(MediaPlayer.rules.SwitchRequest.prototype.NO_CHANGE,MediaPlayer.rules.SwitchRequest.prototype.STRONG))}}},MediaPlayer.rules.LimitSwitchesRule.prototype={constructor:MediaPlayer.rules.LimitSwitchesRule},MediaPlayer.rules.SwitchRequest=function(a,b){"use strict";this.quality=a,this.priority=b,void 0===this.quality&&(this.quality=999),void 0===this.priority&&(this.priority=.5)},MediaPlayer.rules.SwitchRequest.prototype={constructor:MediaPlayer.rules.SwitchRequest,NO_CHANGE:999,DEFAULT:.5,STRONG:1,WEAK:0},MediaPlayer.models.MetricsList=function(){"use strict";return{TcpList:[],HttpList:[],RepSwitchList:[],BufferLevel:[],PlayList:[],DroppedFrames:[]}},MediaPlayer.models.MetricsList.prototype={constructor:MediaPlayer.models.MetricsList},MediaPlayer.vo.SegmentRequest=function(){"use strict";this.action="download",this.startTime=0/0,this.streamType=null,this.type=null,this.duration=0/0,this.timescale=0/0,this.range=null,this.url=null,this.requestStartDate=null,this.firstByteDate=null,this.requestEndDate=null,this.deferred=null},MediaPlayer.vo.SegmentRequest.prototype={constructor:MediaPlayer.vo.SegmentRequest,ACTION_DOWNLOAD:"download",ACTION_COMPLETE:"complete"},MediaPlayer.vo.metrics.BufferLevel=function(){"use strict";this.t=null,this.level=null},MediaPlayer.vo.metrics.BufferLevel.prototype={constructor:MediaPlayer.vo.metrics.BufferLevel},MediaPlayer.vo.metrics.DroppedFrames=function(){"use strict";this.time=null,this.droppedFrames=null},MediaPlayer.vo.metrics.DroppedFrames.prototype={constructor:MediaPlayer.vo.metrics.DroppedFrames},MediaPlayer.vo.metrics.HTTPRequest=function(){"use strict";this.tcpid=null,this.type=null,this.url=null,this.actualurl=null,this.range=null,this.trequest=null,this.tresponse=null,this.tfinish=null,this.responsecode=null,this.interval=null,this.mediaduration=null,this.trace=[]},MediaPlayer.vo.metrics.HTTPRequest.prototype={constructor:MediaPlayer.vo.metrics.HTTPRequest},MediaPlayer.vo.metrics.HTTPRequest.Trace=function(){"use strict";this.s=null,this.d=null,this.b=[]},MediaPlayer.vo.metrics.HTTPRequest.Trace.prototype={constructor:MediaPlayer.vo.metrics.HTTPRequest.Trace},MediaPlayer.vo.metrics.PlayList=function(){"use strict";this.start=null,this.mstart=null,this.starttype=null,this.trace=[]},MediaPlayer.vo.metrics.PlayList.Trace=function(){"use strict";this.representationid=null,this.subreplevel=null,this.start=null,this.mstart=null,this.duration=null,this.playbackspeed=null,this.stopreason=null},MediaPlayer.vo.metrics.PlayList.prototype={constructor:MediaPlayer.vo.metrics.PlayList},MediaPlayer.vo.metrics.PlayList.INITIAL_PLAY_START_REASON="initial_start",MediaPlayer.vo.metrics.PlayList.SEEK_START_REASON="seek",MediaPlayer.vo.metrics.PlayList.Trace.prototype={constructor:MediaPlayer.vo.metrics.PlayList.Trace()},MediaPlayer.vo.metrics.PlayList.Trace.USER_REQUEST_STOP_REASON="user_request",MediaPlayer.vo.metrics.PlayList.Trace.REPRESENTATION_SWITCH_STOP_REASON="representation_switch",MediaPlayer.vo.metrics.PlayList.Trace.END_OF_CONTENT_STOP_REASON="end_of_content",MediaPlayer.vo.metrics.PlayList.Trace.REBUFFERING_REASON="rebuffering",MediaPlayer.vo.metrics.RepresentationSwitch=function(){"use strict";this.t=null,this.mt=null,this.to=null,this.lto=null},MediaPlayer.vo.metrics.RepresentationSwitch.prototype={constructor:MediaPlayer.vo.metrics.RepresentationSwitch},MediaPlayer.vo.metrics.TCPConnection=function(){"use strict";this.tcpid=null,this.dest=null,this.topen=null,this.tclose=null,this.tconnect=null},MediaPlayer.vo.metrics.TCPConnection.prototype={constructor:MediaPlayer.vo.metrics.TCPConnection};