(function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("video.js")):"function"==typeof define&&define.amd?define(["video.js"],t):e.videojsContribAds=t(e.videojs)})(this,function(e){"use strict";function t(t){return{disableNextSnapshotRestore:!1,_contentEnding:!1,_contentHasEnded:!1,_hasThereBeenALoadStartDuringPlayerLife:!1,_hasThereBeenALoadedData:!1,_hasThereBeenALoadedMetaData:!1,_inLinearAdMode:!1,_shouldBlockPlay:!1,_playBlocked:!1,_playRequested:!1,adType:null,VERSION:p,reset:function(){t.ads.disableNextSnapshotRestore=!1,t.ads._contentEnding=!1,t.ads._contentHasEnded=!1,t.ads.snapshot=null,t.ads.adType=null,t.ads._hasThereBeenALoadedData=!1,t.ads._hasThereBeenALoadedMetaData=!1,t.ads._cancelledPlay=!1,t.ads._shouldBlockPlay=!1,t.ads._playBlocked=!1,t.ads.nopreroll_=!1,t.ads.nopostroll_=!1,t.ads._playRequested=!1},startLinearAdMode:function(){t.ads._state.startLinearAdMode()},endLinearAdMode:function(){t.ads._state.endLinearAdMode()},skipLinearAdMode:function(){t.ads._state.skipLinearAdMode()},stitchedAds:function(e){return void 0!==e&&(this._stitchedAds=!!e),this._stitchedAds},videoElementRecycled:function(){if(t.ads.shouldPlayContentBehindAd(t))return!1;if(!this.snapshot)throw new Error("You cannot use videoElementRecycled while there is no snapshot.");var e=t.tech_.src()!==this.snapshot.src,n=t.currentSrc()!==this.snapshot.currentSrc;return e||n},isLive:function(t){return"boolean"==typeof t.ads.settings.contentIsLive?t.ads.settings.contentIsLive:t.duration()===1/0||"8"===e.browser.IOS_VERSION&&0===t.duration()},shouldPlayContentBehindAd:function(t){return!e.browser.IS_IOS&&!e.browser.IS_ANDROID&&t.duration()===1/0},isInAdMode:function(){return this._state.isAdState()},isWaitingForAdBreak:function(){return this._state.isWaitingForAdBreak()},isContentResuming:function(){return this._state.isContentResuming()},isAdPlaying:function(){return this._state.inAdBreak()},inAdBreak:function(){return this._state.inAdBreak()},removeNativePoster:function(){var e=t.$(".vjs-tech");e&&e.removeAttribute("poster")},debug:function(){if(this.settings.debug){for(var t=arguments.length,n=Array(t),o=0;o<t;o++)n[o]=arguments[o];1===n.length&&"string"==typeof n[0]?e.log("ADS: "+n[0]):e.log.apply(e,["ADS:"].concat(n))}}}}function n(e){"playing"===e.type?y(this,e):"ended"===e.type?g(this,e):"loadstart"===e.type||"loadeddata"===e.type||"loadedmetadata"===e.type?m(this,e):"play"===e.type?v(this,e):this.ads.isInAdMode()&&(this.ads.isContentResuming()?h(this,"content",e):h(this,"ad",e))}function o(e){e.ads.contentSrc=e.currentSrc(),e.ads._seenInitialLoadstart=!1;var t=function(){if(!e.ads.inAdBreak()){var t=e.currentSrc();t!==e.ads.contentSrc&&(e.ads._seenInitialLoadstart&&e.trigger({type:"contentchanged"}),e.trigger({type:"contentupdate",oldValue:e.ads.contentSrc,newValue:t}),e.ads.contentSrc=t),e.ads._seenInitialLoadstart=!0}};e.on("loadstart",t)}function r(t,n,o){var r=this,a={};t=t.replace(/{([^}=]+)=([^}]+)}/g,function(e,t,n){return a["{"+t+"}"]=n,"{"+t+"}"}),void 0===n&&(n=!1);var i={};for(var s in void 0!==o&&(i=o),i["{player.id}"]=this.options_["data-player"],i["{mediainfo.id}"]=this.mediainfo?this.mediainfo.id:"",i["{mediainfo.name}"]=this.mediainfo?this.mediainfo.name:"",i["{mediainfo.duration}"]=this.mediainfo?this.mediainfo.duration:"",i["{player.duration}"]=this.duration(),i["{timestamp}"]=(new Date).getTime(),i["{document.referrer}"]=S.referrer,i["{window.location.href}"]=b.location.href,i["{random}"]=Math.floor(1e12*Math.random()),["description","tags","reference_id","ad_keys"].forEach(function(e){r.mediainfo&&r.mediainfo[e]?i["{mediainfo."+e+"}"]=r.mediainfo[e]:a["{mediainfo."+e+"}"]?i["{mediainfo."+e+"}"]=a["{mediainfo."+e+"}"]:i["{mediainfo."+e+"}"]=""}),j(this.mediainfo,i,"custom_fields"),j(this.mediainfo,i,"customFields"),i)t=t.split(s).join(M(i[s],n));for(var d in t=t.replace(/{pageVariable\.([^}]+)}/g,function(t,o){for(var r=void 0,i=b,s=o.split("."),d=0;d<s.length;d++)d===s.length-1?r=i[s[d]]:i=i[s[d]];var l=void 0===r?"undefined":w(r);return null===r?"null":void 0===r?a["{pageVariable."+o+"}"]?a["{pageVariable."+o+"}"]:(e.log.warn('Page variable "'+o+'" not found'),""):"string"!==l&&"number"!==l&&"boolean"!==l?(e.log.warn('Page variable "'+o+'" is not a supported type'),""):M(String(r),n)}),a)t=t.replace(d,a[d]);return t}function a(t,n){n&&e.log("ADS:","Using cancelContentPlay to block content playback"),t.on("play",i)}function i(){var e=this;!1!==e.ads._shouldBlockPlay&&(e.paused()||(e.ads.debug("Playback was canceled by cancelContentPlay"),e.pause()),e.ads._cancelledPlay=!0)}function s(t){var n=void 0;n=e.browser.IS_IOS&&t.ads.isLive(t)&&t.seekable().length>0?t.currentTime()-t.seekable().end(0):t.currentTime();var o=t.$(".vjs-tech"),r=t.textTracks?t.textTracks():[],a=[],i={ended:t.ended(),currentSrc:t.currentSrc(),src:t.tech_.src(),currentTime:n,type:t.currentType()};o&&(i.style=o.getAttribute("style"));for(var s=0;s<r.length;s++){var d=r[s];a.push({track:d,mode:d.mode}),d.mode="disabled"}return i.suppressedTracks=a,i}function d(t,n,o){if(void 0===o&&(o=function(){}),!0===t.ads.disableNextSnapshotRestore)return t.ads.disableNextSnapshotRestore=!1,void o();var r=t.$(".vjs-tech"),a=20,i=n.suppressedTracks,s=void 0,d=function(){for(var e=0;e<i.length;e++)s=i[e],s.track.mode=s.mode},l=function(){var o=void 0;if(e.browser.IS_IOS&&t.ads.isLive(t))n.currentTime<0&&(o=t.seekable().length>0?t.seekable().end(0)+n.currentTime:t.currentTime(),t.currentTime(o));else if(n.ended)t.currentTime(t.duration());else{t.currentTime(n.currentTime);var r=t.play();r&&r.catch&&r.catch(function(t){e.log.warn("Play promise rejected in snapshot resume",t)})}t.ads.shouldRemoveAutoplay_&&(t.autoplay(!1),t.ads.shouldRemoveAutoplay_=!1)},u=function n(){if(t.off("contentcanplay",n),V&&t.clearTimeout(V),r=t.el().querySelector(".vjs-tech"),r.readyState>1)return l();if(void 0===r.seekable)return l();if(r.seekable.length>0)return l();if(a--)t.setTimeout(n,50);else try{l()}catch(t){e.log.warn("Failed to resume the content after an advertisement",t)}};if("style"in n&&r.setAttribute("style",n.style||""),t.ads.videoElementRecycled())t.one("resumeended",o),t.one("contentloadedmetadata",d),e.browser.IS_IOS&&!t.autoplay()&&(t.autoplay(!0),t.ads.shouldRemoveAutoplay_=!0),t.src({src:n.currentSrc,type:n.type}),t.one("contentcanplay",u),V=t.setTimeout(u,2e3);else{if(d(),!t.ended()){var c=t.play();c&&c.catch&&c.catch(function(t){e.log.warn("Play promise rejected in snapshot restore",t)})}o()}}function l(e){e.ads.debug("Starting ad break"),e.ads._inLinearAdMode=!0,e.trigger("adstart"),e.ads.shouldPlayContentBehindAd(e)||(e.ads.snapshot=s(e)),e.ads.shouldPlayContentBehindAd(e)&&(e.ads.preAdVolume_=e.volume(),e.volume(0)),e.addClass("vjs-ad-playing"),e.hasClass("vjs-live")&&e.removeClass("vjs-live"),e.ads.removeNativePoster()}function u(e,t){e.ads.debug("Ending ad break"),void 0===t&&(t=function(){}),e.ads.adType=null,e.ads._inLinearAdMode=!1,e.trigger("adend"),e.removeClass("vjs-ad-playing"),e.ads.isLive(e)&&e.addClass("vjs-live"),e.ads.shouldPlayContentBehindAd(e)?(e.volume(e.ads.preAdVolume_),t()):d(e,e.ads.snapshot,t)}e=e&&e.hasOwnProperty("default")?e.default:e;var c,p="6.4.1",f=function(e,t){t.isImmediatePropagationStopped=function(){return!0},t.cancelBubble=!0,t.isPropagationStopped=function(){return!0}},h=function(e,t,n){f(e,n),e.trigger({type:t+n.type,originalEvent:n})},y=function(e,t){e.ads.isInAdMode()&&(e.ads.isContentResuming()?e.ads._contentEnding&&h(e,"content",t):h(e,"ad",t))},g=function(e,t){e.ads.isInAdMode()?e.ads.isContentResuming()?(f(e,t),e.trigger("resumeended")):h(e,"ad",t):e.ads._contentHasEnded||(h(e,"content",t),e.trigger("readyforpostroll"))},m=function(e,t){if(!("loadstart"===t.type&&!e.ads._hasThereBeenALoadStartDuringPlayerLife||"loadeddata"===t.type&&!e.ads._hasThereBeenALoadedData||"loadedmetadata"===t.type&&!e.ads._hasThereBeenALoadedMetaData))if(e.ads.inAdBreak())h(e,"ad",t);else{if(e.currentSrc()!==e.ads.contentSrc)return;h(e,"content",t)}},v=function(e,t){e.ads.inAdBreak()?h(e,"ad",t):e.ads.isContentResuming()&&h(e,"content",t)},A="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};c="undefined"!=typeof window?window:void 0!==A?A:"undefined"!=typeof self?self:{};var _,b=c,k={},T=(Object.freeze||Object)({default:k}),C=T&&k||T,P=void 0!==A?A:"undefined"!=typeof window?window:{};"undefined"!=typeof document?_=document:(_=P["__GLOBAL_DOCUMENT_CACHE@4"],_||(_=P["__GLOBAL_DOCUMENT_CACHE@4"]=C));var S=_,w="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},R=(function(){function e(e){this.value=e}function t(t){function n(e,t){return new Promise(function(n,r){var s={key:e,arg:t,resolve:n,reject:r,next:null};i?i=i.next=s:(a=i=s,o(e,t))})}function o(n,a){try{var i=t[n](a),s=i.value;s instanceof e?Promise.resolve(s.value).then(function(e){o("next",e)},function(e){o("throw",e)}):r(i.done?"return":"normal",i.value)}catch(e){r("throw",e)}}function r(e,t){switch(e){case"return":a.resolve({value:t,done:!0});break;case"throw":a.reject(t);break;default:a.resolve({value:t,done:!1})}a=a.next,a?o(a.key,a.arg):i=null}var a,i;this._invoke=n,"function"!=typeof t.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(t.prototype[Symbol.asyncIterator]=function(){return this}),t.prototype.next=function(e){return this._invoke("next",e)},t.prototype.throw=function(e){return this._invoke("throw",e)},t.prototype.return=function(e){return this._invoke("return",e)}}(),function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}),L=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},B=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},M=function(e,t){return t?encodeURIComponent(e):e},j=function(e,t,n){if(e&&e[n])for(var o=e[n],r=Object.keys(o),a=0;a<r.length;a++){var i="{mediainfo."+n+"."+r[a]+"}";t[i]=o[r[a]]}},E={processMetadataTracks:function(e,t){for(var n=e.textTracks(),o=function(n){"metadata"===n.kind&&(e.ads.cueTextTracks.setMetadataTrackMode(n),t(e,n))},r=0;r<n.length;r++)o(n[r]);n.addEventListener("addtrack",function(e){o(e.track)})},setMetadataTrackMode:function(e){},getSupportedAdCue:function(e,t){return t},isSupportedAdCue:function(e,t){return!0},getCueId:function(e,t){return t.id}},N=function(e,t){return void 0!==t&&e.ads.includedCues[t]},I=function(e,t){void 0!==t&&""!==t&&(e.ads.includedCues[t]=!0)};E.processAdTrack=function(t,n,o,r){t.ads.includedCues={};for(var a=0;a<n.length;a++){var i=n[a],s=this.getSupportedAdCue(t,i);if(!this.isSupportedAdCue(t,i))return void e.log.warn("Skipping as this is not a supported ad cue.",i);var d=this.getCueId(t,i),l=i.startTime;if(N(t,d))return void e.log("Skipping ad already seen with ID "+d);r&&r(t,s,d,l),o(t,s,d,l),I(t,d)}};var x={},O=e;x.isMiddlewareMediatorSupported=function(){return!O.browser.IS_IOS&&!O.browser.IS_ANDROID&&!!(O.use&&O.middleware&&O.middleware.TERMINATOR)},x.playMiddleware=function(e){return{setSource:function(e,t){t(null,e)},callPlay:function(){if(e.ads&&!0===e.ads._shouldBlockPlay)return e.ads.debug("Using playMiddleware to block content playback"),e.ads._playBlocked=!0,O.middleware.TERMINATOR},play:function(t,n){e.ads&&e.ads._playBlocked&&t&&(e.ads.debug("Play call to Tech was terminated."),e.trigger("play"),e.addClass("vjs-has-started"),e.ads._playBlocked=!1)}}},x.testHook=function(e){O=e};var D=function(){function t(e){R(this,t),this.player=e}return t._getName=function(){return"Anonymous State"},t.prototype.transitionTo=function(e){var t=this.player,n=this;n.cleanup(t);var o=new e(t);t.ads._state=o,t.ads.debug(n.constructor._getName()+" -> "+o.constructor._getName());for(var r=arguments.length,a=Array(r>1?r-1:0),i=1;i<r;i++)a[i-1]=arguments[i];o.init.apply(o,[t].concat(a))},t.prototype.init=function(){},t.prototype.cleanup=function(){},t.prototype.onPlay=function(){},t.prototype.onPlaying=function(){},t.prototype.onEnded=function(){},t.prototype.onAdsReady=function(){e.log.warn("Unexpected adsready event")},t.prototype.onAdsError=function(){},t.prototype.onAdsCanceled=function(){},t.prototype.onAdTimeout=function(){},t.prototype.onAdStarted=function(){},t.prototype.onContentChanged=function(){},t.prototype.onContentResumed=function(){},t.prototype.onReadyForPostroll=function(){e.log.warn("Unexpected readyforpostroll event")},t.prototype.onNoPreroll=function(){},t.prototype.onNoPostroll=function(){},t.prototype.startLinearAdMode=function(){e.log.warn("Unexpected startLinearAdMode invocation (State via "+this.constructor._getName()+")")},t.prototype.endLinearAdMode=function(){e.log.warn("Unexpected endLinearAdMode invocation (State via "+this.constructor._getName()+")")},t.prototype.skipLinearAdMode=function(){e.log.warn("Unexpected skipLinearAdMode invocation (State via "+this.constructor._getName()+")")},t.prototype.isAdState=function(){throw new Error("isAdState unimplemented for "+this.constructor._getName())},t.prototype.isWaitingForAdBreak=function(){return!1},t.prototype.isContentResuming=function(){return!1},t.prototype.inAdBreak=function(){return!1},t.prototype.handleEvent=function(e){var t=this.player;"play"===e?this.onPlay(t):"adsready"===e?this.onAdsReady(t):"adserror"===e?this.onAdsError(t):"adscanceled"===e?this.onAdsCanceled(t):"adtimeout"===e?this.onAdTimeout(t):"ads-ad-started"===e?this.onAdStarted(t):"contentchanged"===e?this.onContentChanged(t):"contentresumed"===e?this.onContentResumed(t):"readyforpostroll"===e?this.onReadyForPostroll(t):"playing"===e?this.onPlaying(t):"ended"===e?this.onEnded(t):"nopreroll"===e?this.onNoPreroll(t):"nopostroll"===e&&this.onNoPostroll(t)},t}(),F=function(e){function t(n){R(this,t);var o=B(this,e.call(this,n));return o.contentResuming=!1,o.waitingForAdBreak=!1,o}return L(t,e),t.prototype.isAdState=function(){return!0},t.prototype.onPlaying=function(){this.contentResuming&&this.transitionTo(G)},t.prototype.onContentResumed=function(){this.contentResuming&&this.transitionTo(G)},t.prototype.isWaitingForAdBreak=function(){return this.waitingForAdBreak},t.prototype.isContentResuming=function(){return this.contentResuming},t.prototype.inAdBreak=function(){return!0===this.player.ads._inLinearAdMode},t}(D),U=function(e){function t(){return R(this,t),B(this,e.apply(this,arguments))}return L(t,e),t.prototype.isAdState=function(){return!1},t.prototype.onContentChanged=function(e){e.ads.debug("Received contentchanged event (ContentState)"),e.paused()?this.transitionTo($):(this.transitionTo(q,!1),e.pause(),e.ads._pausedOnContentupdate=!0)},t}(D),V=void 0,H={start:l,end:u},q=function(t){function n(){return R(this,n),B(this,t.apply(this,arguments))}return L(n,t),n._getName=function(){return"Preroll"},n.prototype.init=function(e,t,n){if(this.waitingForAdBreak=!0,e.addClass("vjs-ad-loading"),n||e.ads.nopreroll_)return this.resumeAfterNoPreroll(e);var o=e.ads.settings.timeout;"number"==typeof e.ads.settings.prerollTimeout&&(o=e.ads.settings.prerollTimeout),this._timeout=e.setTimeout(function(){e.trigger("adtimeout")},o),t?this.handleAdsReady():this.adsReady=!1},n.prototype.onAdsReady=function(t){t.ads.inAdBreak()?e.log.warn("Unexpected adsready event (Preroll)"):(t.ads.debug("Received adsready event (Preroll)"),this.handleAdsReady())},n.prototype.handleAdsReady=function(){this.adsReady=!0,this.readyForPreroll()},n.prototype.afterLoadStart=function(e){var t=this.player;t.ads._hasThereBeenALoadStartDuringPlayerLife?e():(t.ads.debug("Waiting for loadstart..."),t.one("loadstart",function(){t.ads.debug("Received loadstart event"),e()}))},n.prototype.noPreroll=function(){var e=this;this.afterLoadStart(function(){e.player.ads.debug("Skipping prerolls due to nopreroll event (Preroll)"),e.resumeAfterNoPreroll(e.player)})},n.prototype.readyForPreroll=function(){var e=this.player;this.afterLoadStart(function(){e.ads.debug("Triggered readyforpreroll event (Preroll)"),e.trigger("readyforpreroll")})},n.prototype.onAdsCanceled=function(e){var t=this;e.ads.debug("adscanceled (Preroll)"),this.afterLoadStart(function(){t.resumeAfterNoPreroll(e)})},n.prototype.onAdsError=function(t){var n=this;e.log("adserror (Preroll)"),this.inAdBreak()?t.ads.endLinearAdMode():this.afterLoadStart(function(){n.resumeAfterNoPreroll(t)})},n.prototype.startLinearAdMode=function(){var t=this.player;!this.adsReady||t.ads.inAdBreak()||this.isContentResuming()?e.log.warn("Unexpected startLinearAdMode invocation (Preroll)"):(t.clearTimeout(this._timeout),t.ads.adType="preroll",this.waitingForAdBreak=!1,H.start(t),t.ads._shouldBlockPlay=!1)},n.prototype.onAdStarted=function(e){e.removeClass("vjs-ad-loading")},n.prototype.endLinearAdMode=function(){var e=this.player;this.inAdBreak()&&(e.removeClass("vjs-ad-loading"),e.addClass("vjs-ad-content-resuming"),H.end(e),this.contentResuming=!0)},n.prototype.skipLinearAdMode=function(){var t=this,n=this.player;n.ads.inAdBreak()||this.isContentResuming()?e.log.warn("Unexpected skipLinearAdMode invocation"):this.afterLoadStart(function(){n.trigger("adskip"),n.ads.debug("skipLinearAdMode (Preroll)"),t.resumeAfterNoPreroll(n)})},n.prototype.onAdTimeout=function(e){var t=this;this.afterLoadStart(function(){e.ads.debug("adtimeout (Preroll)"),t.resumeAfterNoPreroll(e)})},n.prototype.onNoPreroll=function(t){t.ads.inAdBreak()||this.isContentResuming()?e.log.warn("Unexpected nopreroll event (Preroll)"):this.noPreroll()},n.prototype.resumeAfterNoPreroll=function(e){this.contentResuming=!0,e.ads._shouldBlockPlay=!1,e.paused()&&(e.ads._playRequested||e.ads._pausedOnContentupdate)&&e.play()},n.prototype.cleanup=function(t){t.ads._hasThereBeenALoadStartDuringPlayerLife||e.log.warn("Leaving Preroll state before loadstart event can cause issues."),t.removeClass("vjs-ad-loading"),t.removeClass("vjs-ad-content-resuming"),t.clearTimeout(this._timeout)},n}(F),W=function(e){function t(){return R(this,t),B(this,e.apply(this,arguments))}return L(t,e),t._getName=function(){return"Midroll"},t.prototype.init=function(e){e.ads.adType="midroll",H.start(e),e.addClass("vjs-ad-loading")},t.prototype.onAdStarted=function(e){e.removeClass("vjs-ad-loading")},t.prototype.endLinearAdMode=function(){var e=this.player;this.inAdBreak()&&(this.contentResuming=!0,e.addClass("vjs-ad-content-resuming"),e.removeClass("vjs-ad-loading"),H.end(e))},t.prototype.onAdsError=function(e){this.inAdBreak()&&e.ads.endLinearAdMode()},t.prototype.cleanup=function(e){e.removeClass("vjs-ad-loading"),e.removeClass("vjs-ad-content-resuming")},t}(F),z=function(t){function n(){return R(this,n),B(this,t.apply(this,arguments))}return L(n,t),n._getName=function(){return"Postroll"},n.prototype.init=function(e){if(this.waitingForAdBreak=!0,e.ads._contentEnding=!0,e.ads.nopostroll_)this.resumeContent(e),this.transitionTo(Y);else{e.addClass("vjs-ad-loading");var t=e.ads.settings.timeout;"number"==typeof e.ads.settings.postrollTimeout&&(t=e.ads.settings.postrollTimeout),this._postrollTimeout=e.setTimeout(function(){e.trigger("adtimeout")},t)}},n.prototype.startLinearAdMode=function(){var t=this.player;t.ads.inAdBreak()||this.isContentResuming()?e.log.warn("Unexpected startLinearAdMode invocation (Postroll)"):(t.ads.adType="postroll",t.clearTimeout(this._postrollTimeout),this.waitingForAdBreak=!1,H.start(t))},n.prototype.onAdStarted=function(e){e.removeClass("vjs-ad-loading")},n.prototype.endLinearAdMode=function(){var e=this,t=this.player;this.inAdBreak()&&(t.removeClass("vjs-ad-loading"),this.resumeContent(t),H.end(t,function(){e.transitionTo(Y)}))},n.prototype.skipLinearAdMode=function(){var t=this.player;t.ads.inAdBreak()||this.isContentResuming()?e.log.warn("Unexpected skipLinearAdMode invocation"):(t.ads.debug("Postroll abort (skipLinearAdMode)"),t.trigger("adskip"),this.abort(t))},n.prototype.onAdTimeout=function(e){e.ads.debug("Postroll abort (adtimeout)"),this.abort(e)},n.prototype.onAdsError=function(e){e.ads.debug("Postroll abort (adserror)"),e.ads.inAdBreak()?e.ads.endLinearAdMode():this.abort(e)},n.prototype.onContentChanged=function(e){this.isContentResuming()?this.transitionTo($):this.inAdBreak()||this.transitionTo(q)},n.prototype.onNoPostroll=function(t){this.isContentResuming()||this.inAdBreak()?e.log.warn("Unexpected nopostroll event (Postroll)"):this.abort(t)},n.prototype.resumeContent=function(e){this.contentResuming=!0,e.addClass("vjs-ad-content-resuming")},n.prototype.abort=function(e){this.resumeContent(e),e.removeClass("vjs-ad-loading"),this.transitionTo(Y)},n.prototype.cleanup=function(e){e.removeClass("vjs-ad-content-resuming"),e.clearTimeout(this._postrollTimeout),e.ads._contentEnding=!1},n}(F),$=function(e){function t(){return R(this,t),B(this,e.apply(this,arguments))}return L(t,e),t._getName=function(){return"BeforePreroll"},t.prototype.init=function(e){this.adsReady=!1,this.shouldResumeToContent=!1,e.ads._shouldBlockPlay=!0},t.prototype.onAdsReady=function(e){e.ads.debug("Received adsready event (BeforePreroll)"),this.adsReady=!0},t.prototype.onPlay=function(e){e.ads.debug("Received play event (BeforePreroll)"),this.transitionTo(q,this.adsReady,this.shouldResumeToContent)},t.prototype.onAdsCanceled=function(e){e.ads.debug("adscanceled (BeforePreroll)"),this.shouldResumeToContent=!0},t.prototype.onAdsError=function(){this.player.ads.debug("adserror (BeforePreroll)"),this.shouldResumeToContent=!0},t.prototype.onNoPreroll=function(){this.player.ads.debug("Skipping prerolls due to nopreroll event (BeforePreroll)"),this.shouldResumeToContent=!0},t.prototype.skipLinearAdMode=function(){var e=this.player;e.trigger("adskip"),e.ads.debug("skipLinearAdMode (BeforePreroll)"),this.shouldResumeToContent=!0},t.prototype.onContentChanged=function(){},t}(U),G=function(e){function t(){return R(this,t),B(this,e.apply(this,arguments))}return L(t,e),t._getName=function(){return"ContentPlayback"},t.prototype.init=function(e){e.ads._shouldBlockPlay=!1},t.prototype.onAdsReady=function(e){e.ads.debug("Received adsready event (ContentPlayback)"),e.ads.nopreroll_||(e.ads.debug("Triggered readyforpreroll event (ContentPlayback)"),e.trigger("readyforpreroll"))},t.prototype.onReadyForPostroll=function(e){e.ads.debug("Received readyforpostroll event"),this.transitionTo(z)},t.prototype.startLinearAdMode=function(){this.transitionTo(W)},t}(U),Y=function(t){function n(){return R(this,n),B(this,t.apply(this,arguments))}return L(n,t),n._getName=function(){return"AdsDone"},n.prototype.init=function(e){e.ads._contentHasEnded=!0,e.trigger("ended")},n.prototype.startLinearAdMode=function(){e.log.warn("Unexpected startLinearAdMode invocation (AdsDone)")},n}(U),J=x.playMiddleware,K=x.isMiddlewareMediatorSupported,Q=e.getTech("Html5").Events,X={timeout:5e3,prerollTimeout:void 0,postrollTimeout:void 0,debug:!1,stitchedAds:!1,contentIsLive:void 0},Z=function(i){var s=this,d=e.mergeOptions(X,i),l=Q.concat(["firstplay","loadedalldata","playing"]);s.on(l,n),K()&&d.debug?e.log("ADS:","Play middleware has been registered with videojs"):a(s,d.debug),s.setTimeout(function(){s.ads._hasThereBeenALoadStartDuringPlayerLife||""===s.src()||e.log.error("videojs-contrib-ads has not seen a loadstart event 5 seconds after being initialized, but a source is present. This indicates that videojs-contrib-ads was initialized too late. It must be initialized immediately after video.js in the same tick. As a result, some ads will not play and some media events will be incorrect. For more information, see http://videojs.github.io/videojs-contrib-ads/integrator/getting-started.html")},5e3),s.on("ended",function(){s.hasClass("vjs-has-started")||s.addClass("vjs-has-started")}),s.on("contenttimeupdate",function(){s.removeClass("vjs-waiting")}),s.on(["addurationchange","adcanplay"],function(){if((!s.ads.snapshot||s.currentSrc()!==s.ads.snapshot.currentSrc)&&s.ads.inAdBreak()){var t=s.play();t&&t.catch&&t.catch(function(t){e.log.warn("Play promise rejected when playing ad",t)})}}),s.on("nopreroll",function(){s.ads.debug("Received nopreroll event"),s.ads.nopreroll_=!0}),s.on("nopostroll",function(){s.ads.debug("Received nopostroll event"),s.ads.nopostroll_=!0}),s.on("playing",function(){s.ads._cancelledPlay=!1,s.ads._pausedOnContentupdate=!1}),s.on("play",function(){s.ads._playRequested=!0}),s.one("loadstart",function(){s.ads._hasThereBeenALoadStartDuringPlayerLife=!0}),s.on("loadeddata",function(){s.ads._hasThereBeenALoadedData=!0}),s.on("loadedmetadata",function(){s.ads._hasThereBeenALoadedMetaData=!0}),s.ads=t(s),s.ads.settings=d,s.ads._state=new $(s),s.ads._state.init(s),s.ads.stitchedAds(d.stitchedAds),s.ads.cueTextTracks=E,s.ads.adMacroReplacement=r.bind(s),o(s),s.on("contentchanged",s.ads.reset);var u=function(){return!s.ads.shouldPlayContentBehindAd(s)&&s.ads.inAdBreak()&&s.tech_.featuresNativeTextTracks&&e.browser.IS_IOS&&!Array.isArray(s.textTracks())},c=function(){var e=s.textTracks();if(u())for(var t=0;t<e.length;t++){var n=e[t];"showing"===n.mode&&(n.mode="disabled")}};s.ready(function(){s.textTracks().addEventListener("change",c)}),s.on(["play","playing","ended","adsready","adscanceled","adskip","adserror","adtimeout","ads-ad-started","contentchanged","contentresumed","readyforpostroll","nopreroll","nopostroll"],function(e){s.ads._state.handleEvent(e.type)}),s.on("dispose",function(){s.textTracks().removeEventListener("change",c)})},ee=e.registerPlugin||e.plugin;return ee("ads",Z),K()&&e.use("*",J),Z});