import {clpp} from "./cl.core.js";import './cl.mse.js';let g={};const _ = clpp._;var f=function(window){'use strict';var WM="An unknown error occurred while trying to get volume",XM="Cannot get loading rendition due to platform limitations",YM="SecurityError",ZM="The require privilege is: http://tizen.org/privilege/tv.audio",$M="|STARTBITRATE\x3d",aN=function(a,b,c){const d=e=>{c.call(a,e);a.removeEventListener(b,d)};a.addEventListener(b,d)},dN=function(a){return _.x(function*(){if(a.a!==_.td&&a.a!==_.rd)throw new _.I(_.G,6,6001,`The key system ${a.a} is not supported by `+"the player or the platform");
const b=a.f.get(a.a);if(!b.ud)throw new _.I(_.G,6,6012,`No license server given for ${a.a}`);try{a.a===_.td?yield bN(a):yield cN(a,b),a.o={keySystem:a.a,licenseServerUri:b.ud,distinctiveIdentifierRequired:!1,persistentStateRequired:b.Ue,audioRobustness:"",videoRobustness:"",serverCertificate:null,initData:[],keyIds:[],periodId:null}}catch(c){throw a.g.error(`Error while configuring CDM for ${a.a}`,c),new _.I(_.G,6,6005,{message:JSON.stringify(c)});}})},fN=function(a,b){_.x(function*(){var c=a.f.get(a.a);
a.g.debug("DRM Challenge data: ",b.challenge);const d=atob(b.challenge);var e=new Uint8Array(d.length);for(let h=0;h<d.length;++h)e[h]=d.charCodeAt(h);c=_.mj([b.serverurl&&""!==b.serverurl?b.serverurl:c.ud],_.ij());c.type=3;c.body=e.buffer;c.method=_.cb;try{var f=yield a.D.vb.fetch(c).T;if(a.j){var g=_.K(f.data);const h=g.byteLength;e="";for(f=0;f<h;f++)e+=String.fromCharCode(g[f]);const k=`${b.session_id}PARAM_START_POSITION`+`${btoa(e)}PARAM_START_POSITION`;a.g.debug("Widevine license params",k);
try{webapis.avplay.setDrm(eN,"widevine_license_data",k)}catch(l){a.g.error("License response rejected by CDM");const m=new _.I(_.G,6,6008,{browserError:JSON.stringify(l)});a.D.onError(m)}}}catch(h){a.g.error("License request failed.",JSON.stringify(h)),g=new _.I(_.G,6,6007,{message:"Error while fetching license!",url:h.data.url,status:h.data.status||NaN,response:h.data.response||"",headers:h.data.headers||{}},h),a.D.onError(g)}})},bN=function(a){return _.x(function*(){try{webapis.avplay.setDrm(eN,
"Initialize",""),webapis.avplay.setDrm(eN,"widevine_app_session",a.l.id),webapis.avplay.setDrm(eN,"widevine_data_type",a.l.type)}catch(b){throw b;}})},cN=function(a,b){return _.x(function*(){var c={};c[gN]=!b.Ue;c[hN]=b.ud;""!==b.customData&&(c[iN]=b.customData);c=JSON.stringify(c);a.g.debug("PlayReady properties: ",c);try{webapis.avplay.setDrm(jN,"SetProperties",c)}catch(d){throw d;}})},lN=function(a,b){if(a.f!==b)if(a.f===_.Mo&&b!==_.To)a.g.debug(_.yB+`${kN(b)}`);else{var c=(new Date).getTime();
a.j=a.f;a.f=b;a.f===_.Po?(a.o=(new Date).getTime(),a.m.trigger(new _.F(_.Nc,{detail:{bufferedTimeMS:-1,reason:a.h}}))):a.j===_.Po&&a.m.trigger(new _.F(_.Mc,{detail:{bufferedTimeMS:c-a.o,reason:a.h}}));b={currentState:a.f,previousState:a.j,timeSinceLastStateChangeMS:c-a.w};a.w=c;a.m.trigger(new _.F(_.Kf,{detail:b}));a.g.debug("State changed:",kN(a.j),"-\x3e",kN(a.f))}},kN=function(a){return Object.keys(_.So)[a]},oN=function(a){if(a.l){var b=a.a.getState(),c=a.f;switch(b){case mN:c=_.Wo;break;case nN:c=
_.Vo;break;default:a.m.isEnded()?c=_.Lo:a.g.debug("Inconsistent AVPlay playback state:",b)}lN(a,c)}},pN=function(a){return _.x(function*(){const b=a.m.getConfiguration();let c;(c=yield _.Xs(a.B.url,a.m.getNetworkEngine(),b.manifest.attemptParameters,a.B.type||null))&&c.configure(b.manifest);return c})},qN=function(a){if(!a)return!1;a=a.periods;let b=!1;for(let c=0;c<a.length;c++)b=b||0<a[c].textStreams.length;return b},rN=function(a){const b=document.createElement(_.w),c=new _.zI,d=new _.GH,e=a.m.getTextDisplayer();
return new _.AI(b,c,e,d,a.m.getConfiguration())},sN=function(a){const b={configuration:{},Ib:()=>a.m.getPosition(),aa:a.h,vb:a.m.getNetworkEngine(),Kc:null,Pe:a.G.bind(a),Oe:a.F.bind(a),onError:a.H.bind(a),og:()=>{},onEvent:()=>{},sg:a.I.bind(a),ge:()=>{},gd:()=>new _.xJ,ve:()=>!1,ed:null};return new _.VI(a.a,b)},tN=function(a){const b=a.m.getPosition();let c=null;for(const d of a.a.periods)d.startTime<=b&&(c=d);return c},uN=function(a){a.g.debug("getTextStreams()",a.a);if(a.a){var b=[],c=a.a.periods;
a.g.debug("getting text streams");for(var d=0;d<c.length;d++)if(a.g.debug(c[d].startTime,a.m.getPosition()),c[d].startTime<=a.m.getPosition()){b=c[d].textStreams;break}a=b}else a=[];b=[];c=0;for(d=0;d<a.length;d++){const e=new _.Ij(String(c++),_.L);e.mimeType=a[d].mimeType;e.language=a[d].language;e.roles=a[d].roles;e.kind=a[d].kind||_.YB;const f=new _.Qj(String(a[d].id),e);f.bandwidth=a[d].bandwidth||null;e.renditions.push(f);b.push(e)}return b},vN=function(a){if(a.h&&!a.h.getTextDisplayer().isTextVisible())return null;
if(a.f){const b=_.vG(a.f,_.H);let c=null;if(b){a=uN(a);for(let d=0;d<a.length;d++)if(a[d].renditions[0].id===String(b.id)){c=a[d].renditions[0];break}}return c}return null},wN=function(a,b){a.g.debug("Set active track",b);if(b&&(a.o=b.language,a.A=b.roles[0]||"",a.C=b.kind===_.Ud,a.a&&a.f)){a.setTextVisibility(!0);const c=tN(a),d=b.renditions[0];(b=c.textStreams.find(e=>String(e.id)===d.id))?(a.w?(a.g.debug("Switching period defer text selection"),a.l=b):(_.IG(a.f,b,!0,0),a.m.trigger(new _.F(_.Uf))),
a.o=b.language):a.g.error("No stream with id",d.id)}},xN=function(a){const b=a.na();b&&a.m.trigger(new _.F(_.Kc,{detail:{width:b.width,height:b.height,bandwidth:b.bandwidth,rendition:b}}))},yN=function(a,b){a.m.trigger(new _.F(_.rg,{details:{width:b.width,height:b.height,bandwidth:b.bandwidth,track:b.track,abrSelection:a.a.o}}))},zN=function(a,b){let c=null;try{c=JSON.parse(b)}catch(d){a.g.warn("Couldn't retrieve extra infos from stream."),c=null}return c},AN=function(a,b){a=a.f[_.N]||[];const c=
[];for(let d=0;d<a.length;d++)for(let e=0;e<a[d].renditions.length;e++)_.eh(a[d].renditions[e],b,Object.keys(b))&&c.push(a[d].renditions[e]);return c[0]||null},BN=function(a){const b=a.m.getConfiguration();var c=_.$h(b.preferredAudioLanguage||[]);const d=a.f[_.M]||[];if(d.length){var e=null;c.some(g=>{e=_.tC(g,d.map(h=>h.language));return!!e});if(e){var f=d.filter(g=>g.language===e);c=f[0];1<f.length&&b.preferredAudioRole&&(f=f.filter(g=>0<=g.roles.indexOf(b.preferredAudioRole)),0<f.length&&(c=f[0]));
a.g.debug("Setting audio track with preferred language:",e);a.xa(c)}else a.g.debug("Preferred language(s) not available")}else a.g.debug("Could not set preferred audio language")},HN=function(a,b){var c=(l,m)=>{for(let n=0;n<l.length;n++)if(l[n].language===m)return l[n];return null};const d={};if(0>=b.length)return d;var e=b.filter(l=>l.type===CN),f=b.filter(l=>l.type===DN);const g=[];for(var h=0;h<f.length;h++){const l=zN(a,f[h].extra_info);if(l){var k=_.Bi(l.language||_.dg);k=_.Cj(k);k=c(g,k);k||
(k=new _.Ij(String(a.h++),_.M),g.push(k));k.renditions.push(EN(f[h].index,l,k))}else a.g.warn("Skipping audio stream with no extra info")}c=new _.Ij(String(a.h++),_.N);for(f=0;f<e.length;f++)(h=zN(a,e[f].extra_info))?c.renditions.push(FN(e[f].index,h,c)):a.g.warn("Skipping video stream with no extra info");e=[];e=a.j?uN(a.j):GN(a,b);d[_.N]=[c];d[_.M]=g;d[_.L]=e;return d},KN=function(a,b){if(b===_.L&&a.j)return vN(a.j);var c=IN(a.a)||[];if(0===c.length)return null;c=c.filter(e=>e.type===b.toUpperCase())[0];
var d=null;b===_.N&&(d=zN(a,c.extra_info),d=AN(a,{width:d.Width,height:d.Height}));b===_.M&&(c?(d=JN(a,c,_.M),a.l=d):d=a.l);b===_.L&&(c?(d=JN(a,c,_.L),a.o=d):d=a.o);return d},NN=function(a,b){if(b){const c=b.track.type.toUpperCase();LN(a.a,c,Number(b.id)).then(()=>{c===DN&&(a.l=b,a.m.trigger(new _.F(_.Ic)));c===MN&&(a.o=b,a.m.trigger(new _.F(_.Uf)))}).catch(()=>{a.g.error("Could not select "+c+" track.")})}else a.g.debug("Must provide valid rendition")},EN=function(a,b,c){const d=_.Bi(b.language||
_.dg);c.language=_.Cj(d);c.originalLanguage=d;c.channelsCount=b.channels?Number(b.channels):null;c.mimeType=_.Fc;a=new _.Qj(String(a),c);a.track=c;a.codec=b.fourCC||null;a.bandwidth=b.bit_rate||null;return a},FN=function(a,b,c){c.mimeType=_.pg;a=new _.Qj(String(a),c);a.track=c;a.width=b.Width||null;a.height=b.Height||null;a.bandwidth=b.Bit_rate?Number(b.Bit_rate):null;a.codec=b.fourCC||null;return a},ON=function(a,b,c){b=_.Bi(b.track_lang||_.dg);c.mimeType="text/ttml";c.language=_.Cj(b);c.originalLanguage=
b;c.kind=_.YB;return new _.Qj(String(a),c)},GN=function(a,b){b=b.filter(d=>d.type===MN);const c=[];for(let d=0;d<b.length;d++){const e=zN(a,b[d].extra_info);if(!e){a.g.warn("Skipping text stream with no extra info");continue}const f=new _.Ij(String(a.h++),_.L);f.renditions.push(ON(b[d].index,e,f));c.push(f)}return c},JN=function(a,b,c){a=a.f[c]||[];b=String(b.index);c=null;for(let d=0;d<a.length;d++)for(let e=0;e<a[d].renditions.length;e++)if(a[d].renditions[e].id===b){c=a[d].renditions[e];break}return c},
PN=function(a){return a.f&&a.a?a.a.Ii:webapis.avplay.getTotalTrackInfo()},RN=function(a,b,c){a.g.debug("switchVideoTrack()");try{const d={estimatedBandwidth:parseInt(webapis.avplay.getStreamingProperty("CURRENT_BANDWITH"),10),currentBandwidth:b,nextBandwidth:c,currentPosition:a.getPosition()};a.a=QN(a);a.f=!0;webapis.avplay.stop();webapis.avplay.close();return a.load(a.m.getConfiguration(),d).then(()=>{const e=a.a.Hf;a.f=!1;a.a=null;return e===nN?a.pause():a.play()})}catch(d){return Promise.reject(d)}},
SN=function(a,b){var c=a.m.getTextDisplayer();c&&c.setTextVisibility(b);c=a.m.h;try{c||webapis.avplay.setSilentSubtitle(!b)}catch(d){a.g.debug("Could not set text track visibility",d)}},LN=function(a,b,c){b=b.toUpperCase();b===MN&&SN(a,!0);const d=a.j[b];d&&(d.pe.stop(),a.j[b]=null,a.g.debug(`Cancelled pending track switch for ${b}`));return new Promise((e,f)=>{const g=(h,k,l)=>{l=void 0===l?!1:l;try{webapis.avplay.setSelectTrack(h,k),a.j[h]=null,e()}catch(m){a.g.debug(`Could not set ${h} track. Trying again...`+
`AVPlay state: ${a.getState()}, `+`buffering: ${a.w}`,m),!1===l&&(a.j[h]={type:h,index:k,Df:0,pe:new _.rk(()=>g(h,c,!0))}),(k=a.j[h])&&3>k.Df?(!a.w&&++k.Df,k.pe.ka(a.w?.5:.25)):(a.g.debug("Could not set track after multiple attempts.Giving up..."),k&&k.pe.stop(),a.j[h]=null,f())}};g(b,c)})},IN=function(a){return a.f&&a.a?a.a.kh:webapis.avplay.getCurrentStreamInfo()},TN=function(a){return _.x(function*(){tizen.systeminfo.getPropertyValue("DISPLAY",b=>{a.A=b.resolutionWidth/1920;a.g.debug("Display resolution ratio: ",
a.A)},b=>{a.g.debug("Could not load DISPLAY property");throw b;})})},VN=function(a){try{webapis.avplay.setListener({onbufferingstart:a.J.bind(a),onbufferingprogress:a.I.bind(a),onbufferingcomplete:a.H.bind(a),onstreamcompleted:a.M.bind(a),oncurrentplaytime:b=>{a.trigger(new _.F(UN,{currentTime:b}))},onevent:a.L.bind(a),onsubtitlechange:a.P.bind(a),ondrmevent:a.K.bind(a),onerror:a.B.bind(a)})}catch(b){a.g.error(b)}},WN=function(a){const b=!!a.m.getTrackManager().Qa();try{webapis.avplay.setSilentSubtitle(!b)}catch(c){a.g.debug("Could not set AVPlay subtitle config",
c)}},XN=function(a,b){try{const c=b.estimatedBandwidth||0,d=b.currentBandwidth||0;a.g.debug({estimatedBandwidth:c,Yi:d});0!==c&&0!==d&&c>=1.15*d&&webapis.avplay.setStreamingProperty("ADAPTIVE_INFO",$M+d)}catch(c){a.g.debug(c)}},YN=function(a,b){try{webapis.avplay.setStreamingProperty("ADAPTIVE_INFO","|BITRATES\x3d"+b+$M+b)}catch(c){throw a.g.debug("Could not set fixed bandwidth",c),c;}},ZN=function(a){let b=null;try{b=tizen.tvaudiocontrol.isMute()}catch(c){switch(c.name){case YM:a.g.warn("The application doesn't have the privilege to get the mute state.",
ZM);break;default:a.g.warn(WM,c)}}return!!b},QN=function(a){return{position:a.getPosition(),state:a.m.getState(),Hf:a.getState(),playbackRate:a.getPlaybackRate(),isLive:a.isLive(),duration:a.getDuration(),isMuted:ZN(a),volume:a.getVolume(),Ii:PN(a),kh:IN(a)}},$N=function(){return new Promise((a,b)=>{if(window.webapis)a();else{const c=document.createElement("script");aN(c,_.ke,d=>a(d));aN(c,_.q,d=>b(d));c.src="$WEBAPIS/webapis/webapis.js";document.querySelector("head").appendChild(c)}})},aO=function(a){return _.x(function*(){yield $N();
const b=new Promise(c=>{(new _.rk(c)).ka(5)});if(!(yield Promise.race([TN(a).then(()=>!0),b.then(()=>!1)])))return a.g.debug("Took to long for the SDK to be ready"),Promise.reject("SDK Timeout")})},bO=function(a){return _.x(function*(){a.g.debug("avplay.prepare()");return new Promise((b,c)=>{try{webapis.avplay.prepareAsync(()=>{a.g.debug("AVPlay is ready!");WN(a);b()},d=>{a.g.debug("prepareAsync failed",d);c(d)})}catch(d){a.g.debug("Failed to prepare media player for playback"),c(d)}})})},cO=function(a,
b){try{tizen.tvaudiocontrol.setMute(b)}catch(c){switch(c.name){case YM:a.g.warn("The application does not have the privilege to set mute.",ZM);break;default:a.g.warn(WM,c)}}},hO=function(a,b,c){return _.x(function*(){a.l=_.Zo(b);const d=a.G,e=c||{estimatedBandwidth:0,currentBandwidth:0,nextBandwidth:null,currentPosition:0};a.g.debug(`Loading manifest URL: ${a.l[d].url}`);let f=b.startTime||void 0;a.f&&(a.trigger(new _.F(dO)),f=c.currentPosition);try{let g=a.l[d].url;if(a.l[d].type===_.tc&&!g.includes(".mpd")){const h=
new URL(g);h.searchParams.append("cl-ext",".mpd");g=h.toString()}webapis.avplay.open(g);e.nextBandwidth?(YN(a,e.nextBandwidth),a.o=!1):(a.o||XN(a,e),a.o=!0);VN(a);if(b.drm&&b.drm.env){const h={onError:k=>a.m.onError(k),vb:a.m.getNetworkEngine()};a.h=new eO(b.drm,h);yield a.h.init()}else a.g.debug("No DRM configuration was provided. Assuming clear content");a.f||a.trigger(new _.F(fO));yield bO(a);a.f||a.trigger(new _.F(gO));f&&typeof f===_.t&&0<f&&a.seek(f).catch(h=>{a.g.debug("Couldn't set start position",
h)});a.f||(b.volume&&a.setVolume(b.volume),b.muted&&cO(a,b.muted),b.autoplay&&a.m.play().catch(h=>{a.g.debug("Autoplay failed",h)}))}catch(g){throw a.g.debug("Error while attempting to load source."),g;}})},iO=function(a){if("NONE"!==a.a.getState()){var b=a.j.getBoundingClientRect();{a=a.a;const c=Math.floor(b.left*a.A),d=Math.floor(b.top*a.A),e=Math.floor(b.width*a.A);b=Math.floor(b.height*a.A);a.g.debug("Setting display area to","x:",c,"y:",d,"width:",e,"height:",b);webapis.avplay.setDisplayRect(c,
d,e,b);0===c&&0===d&&1920===e&&1080===b&&webapis.avplay.setDisplayMethod("PLAYER_DISPLAY_MODE_LETTER_BOX")}}else a.g.debug("Could not apply dimension. Player state "+a.a.getState())},eO=class{constructor(a,b){this.h=a;this.o=null;this.a=_.Be;this.l=null;this.j=!1;this.f=new Map;this.D=b;this.g=new _.S("clpp.tizen.DrmEngine")}init(){const a=this;return _.x(function*(){var b=_.Ql[a.h.env]||null;if(!b)throw a.g.debug(_.va,_.gb+a.h.env+_.aa),new _.I(_.G,6,6015,`DRM environment '${a.h.env}' is missing.`);
a.l={id:String(Math.floor(1E4*Math.random())),type:"MPEG-DASH"};var c=Object.keys(a.h.customData||{}).length?btoa(JSON.stringify(a.h.customData)):"";b=_.Sl(b,a.h.customData);const d=b[_.rd];d&&a.f.set(_.rd,{ud:d.licenseUrl||"",customData:c,Ue:!1});(b=b[_.td])&&a.f.set(_.td,{ud:b.licenseUrl||"",customData:c,Ue:!1});if(0===a.f.size)throw new _.I(_.G,6,6E3);if((c=a.h.preferredDrmSystem)&&a.f.get(c))a.a=c;else if(a.f.get(_.rd))a.a=_.rd;else if(a.f.get(_.td))a.a=_.td;else throw new _.I(_.G,6,6001,"Configuration for the target system is missing.");
yield dN(a);a.j=!0})}release(){const a=this;return _.x(function*(){a.j=!1;a.o=null;a.a=_.Be;a.l=null;a.f=new Map})}getDrmInfo(){return this.o}},gN="DeleteLicenseAfterUse",hN="LicenseServer",iN="CustomData";var oO=class{constructor(a){this.m=a;this.a=this.m.a;this.f=_.To;this.j=_.hv;this.w=(new Date).getTime();this.l=!1;this.o=-1;this.h=2;this.g=new _.S("clpp.tizen.StateManager")}initialize(){this.a.on(dO,this.C,this);this.a.on(jO,this.B,this);this.a.on(kO,this.A,this);this.a.on(fO,this.H,this);this.a.on(gO,this.G,this);this.a.on(lO,this.F,this)}release(){lN(this,_.To);this.l=!1;this.o=-1;this.h=2}destroy(){this.release();this.a.off(dO,this.C);this.a.off(jO,this.B);this.a.off(kO,this.A);this.a.off(fO,
this.H);this.a.off(gO,this.G);this.a.off(lO,this.F);this.m=this.a=null}C(){this.g.debug("Buffering start. Player state: ",this.a.getState());this.h=this.a.C?1:2;lN(this,_.Po)}B(a){this.g.debug("Buffering progress: "+a.percent+" %. Player state: ",kN(this.f))}A(){this.g.debug("Buffering complete. Player state: ",this.a.getState());if(!this.l){this.l=!0;var a=this.m.getConfiguration().autoplay;const b=this.a.getState()===mO;if(!a&&b){lN(this,_.Vo);return}}if(a=this.f!==_.Uo)a=this.a.getState(),a=a===
mN||a===nN;a&&oN(this)}H(){this.g.debug("Preparing starts. AVPlay State: ",this.a.getState());this.a.getState()===nO?lN(this,_.Uo):this.g.error("AVPlay prepares while state is not IDLE")}G(){this.g.debug("Preparing ends: AVPlay state:",this.a.getState())}F(){lN(this,_.Lo)}getState(){return this.f}};var pO=class{constructor(){this.o=this.A=this.f=this.h=this.B=this.m=this.j=this.a=null;this.C=!1;this.w=!0;this.l=null;this.g=new _.S("clpp.tizen.TextStreamer")}initialize(a){this.m=a}load(a){const b=this;return _.x(function*(){if(b.m)if(b.B=a,b.j=yield pN(b),b.j){var c={configurationId:"",networkingEngine:b.m.getNetworkEngine(),onContentSteeringInfoFound:()=>null,filterNewPeriod:()=>{},filterAllPeriods:()=>{},onEvent:()=>{},onError:()=>{}};try{b.a=yield b.j.start(a.url,c)}catch(d){b.g.warn(d);try{b.a=
yield b.j.start(a.url.replace("https://","http://"),c)}catch(e){b.g.error(e),b.a=null}}if(b.a&&qN(b.a)){b.h=rN(b);try{yield b.h.open();b.f=sN(b);const d=b.m.getConfiguration();b.f.h=d.streaming;b.o=d.preferredTextLanguage;b.A=d.preferredTextRole;b.C=d.preferForcedSubtitles}catch(d){b.g.debug("Could not setup media source..."),b.h=null,b.f=null,b.j=null,b.a=null}}}else b.g.debug("Could not find manifest parser for source. Make sure parsers are registered.");else b.g.debug("Text streamer is not initialized. Will not load()")})}G(a){this.g.debug(_.RB,
a);this.w=!0;let b=_.NF(a.textStreams,this.o||"",this.A||"",this.C)[0]||null;this.l&&(a.textStreams.includes(this.l)&&(b=this.l),this.l=null);return{video:null,audio:null,text:b,Za:null}}F(){this.g.debug("canSwitch_");this.w=!1;this.l&&(_.IG(this.f,this.l,!0,0),this.l=null)}H(){this.g.debug("onError_")}I(){this.j&&this.j.update&&this.j.update()}start(){const a=this;return _.x(function*(){if(a.f)try{a.f.start()}catch(b){a.g.error("Error while starting streaming engine",b)}})}setTextVisibility(a){this.g.debug("Set text visibility",
a);this.h&&this.h.getTextDisplayer().setTextVisibility(a)}release(){const a=this;return _.x(function*(){a.m=null;a.a=null;a.B=null;a.A=null;a.o=null;a.w=!0;a.l=null})}destroy(){const a=this;return _.x(function*(){a.j&&(yield a.j.stop(),a.j=null);a.f&&(yield a.f.destroy(),a.f=null,a.w=!0);a.h&&(yield a.h.destroy(),a.h=null)})}};var tO=class extends _.T{constructor(){super();this.j=this.a=this.m=null;this.f={};this.g=new _.S("clpp.tizen.TrackManager");this.w=this.o=this.l=null;this.B=!1;this.h=1}C(a){var b=a.eventid;a=a.data;switch(b){case qO:0<Object.keys(this.f).length||(this.g.debug("Loading track manager!"),this.load());b=webapis.avplay.getCurrentStreamInfo();0<b.length&&(b=+zN(this,b[0].extra_info).Bit_rate,b=AN(this,{bandwidth:b}))&&(this.w=b,yN(this,b));break;case rO:xN(this);break;default:this.g.debug("Event type: "+
b+" data: "+a)}}A(a){a.detail.currentState===_.Wo&&this.m.off(_.Kf,this.A)}initialize(a){this.m=a;this.a=this.m.a;this.m.on(_.Kf,b=>{this.B||(b=b.detail,b.currentState===_.Wo&&(this.g.debug("Current state",b.currentState),this.B=!0,BN(this)))});this.a.on(sO,this.C,this)}release(){this.f={};this.j=this.w=this.o=this.l=null;this.B=!1;this.h=1}load(){if(this.a&&!(0<Object.keys(this.f).length)){this.j=this.m.h;this.m.off(_.Kf,this.A);this.m.on(_.Kf,this.A,this);try{const a=PN(this.a);this.f=HN(this,a);
const b=this.f[_.M]||[];b.length&&(this.l=b[0].renditions[0]||null);xN(this)}catch(a){this.g.debug("Could not load track manager")}}}destroy(){this.a.off(sO,this.C);this.a=this.m=null}getVideoTracks(){return this.f[_.N]||[]}getAudioTracks(){return this.f[_.M]||[]}ma(){return this.f[_.L]||[]}na(){return KN(this,_.N)}Ma(){return KN(this,_.M)}Qa(){return KN(this,_.L)}rb(){return this.w}Fb(){this.g.info(XM);return null}Gb(){this.g.info(XM);return null}Ea(){const a=this.na();return a?a.track:null}qa(){const a=
this.Ma();return a?a.track:null}wa(){const a=this.Qa();return a?a.track:null}Ab(a){null===a?(a=this.na(),RN(this.a,a.bandwidth,null).then(()=>{xN(this)})):0<a.renditions.length&&this.jb(a.renditions[0])}xa(a){a?NN(this,a.renditions[0]):this.g.warn("Cannot disable audio tracks on this platform.","Consider muting audio instead...")}Sa(a){a?(a=a.renditions[0],this.j?wN(this.j,a.track):NN(this,a)):(this.g.debug("Disabling text tracks"),this.o=null,SN(this.a,!1),this.m.trigger(new _.F(_.Uf)))}jb(a){const b=
this.na();this.a.o||a.width!==b.width||a.height!==b.height||a.bandwidth!==b.bandwidth?(this.w=a,yN(this,a),RN(this.a,b.bandwidth,a.bandwidth).then(()=>{xN(this)}).catch(c=>{const d=new _.I(_.G,7,7200,{tizenerror:c});this.g.debug("Error while switching video track",c);this.m.onError(d)})):this.g.debug("Trying to switch to already active rendition. Doing nothing...")}yb(a){NN(this,a)}zb(a){this.j?wN(this.j,a.track):NN(this,a)}addTextTrack(){}ta(){return this.a.o}};tO.prototype.isAbrEnabled=tO.prototype.ta;
tO.prototype.addTextTrack=tO.prototype.addTextTrack;tO.prototype.setTextRendition=tO.prototype.zb;tO.prototype.setAudioRendition=tO.prototype.yb;tO.prototype.setVideoRendition=tO.prototype.jb;tO.prototype.setTextTrack=tO.prototype.Sa;tO.prototype.setAudioTrack=tO.prototype.xa;tO.prototype.setVideoTrack=tO.prototype.Ab;tO.prototype.getTextTrack=tO.prototype.wa;tO.prototype.getAudioTrack=tO.prototype.qa;tO.prototype.getVideoTrack=tO.prototype.Ea;tO.prototype.getLoadingTextRendition=tO.prototype.Gb;
tO.prototype.getLoadingAudioRendition=tO.prototype.Fb;tO.prototype.getLoadingVideoRendition=tO.prototype.rb;tO.prototype.getTextRendition=tO.prototype.Qa;tO.prototype.getAudioRendition=tO.prototype.Ma;tO.prototype.getVideoRendition=tO.prototype.na;tO.prototype.getTextTracks=tO.prototype.ma;tO.prototype.getAudioTracks=tO.prototype.getAudioTracks;tO.prototype.getVideoTracks=tO.prototype.getVideoTracks;var xO=class extends _.su{constructor(a){super();this.m=a;this.h=null;this.g=new _.S("clpp.tizen.Middleware");this.F=1;this.C=!1;this.l=null;this.G=0;this.o=!0;this.f=!1;this.a=null;this.A=1;this.w=!1;this.j={}}J(){this.w=!0;this.f||this.trigger(new _.F(dO))}I(a){this.w=!0;this.trigger(new _.F(jO,{percent:a}))}H(){this.w=!1;this.trigger(new _.F(kO))}M(){this.trigger(new _.F(lO))}L(a,b){this.trigger(new _.F(sO,{eventid:a,data:b}))}P(a,b,c,d,e){this.trigger(new _.F(uO,{duration:a,text:b,subtitleType:c,
attriCount:d,attributes:e}))}K(a,b){this.trigger(new _.F(vO,{drmType:a,drmData:b}));this.h&&(a=this.h,a.j&&(a.a===_.td&&"Challenge"===b.name?fN(a,b):"DrmError"===b.name&&(a.g.debug("DrmError event",b),b=new _.I(_.G,6,6005,{message:JSON.stringify(b)}),a.D.onError(b))))}B(a){this.trigger(new _.F(wO,{eventType:a}))}play(){const a=this.getState(),b=()=>new Promise((c,d)=>{let e=null;const f=()=>{c();clearTimeout(e)};this.one(UN,f,this);e=setTimeout(()=>{this.off(UN,f);d("Timeout")},3E4)});if(a===nO)return(new Promise((c,
d)=>{webapis.avplay.prepareAsync(()=>{WN(this);c(webapis.avplay.play())},e=>{this.trigger(new _.F(wO));d(e)})})).then(()=>b());if(a===nN||a===mO)try{return webapis.avplay.play(),b()}catch(c){return Promise.reject(c)}return a===mN?Promise.resolve():Promise.reject("Player is in invalid state")}pause(){try{webapis.avplay.pause()}catch(a){Promise.reject(a)}return this.getState()===nN?Promise.resolve():Promise.reject()}setPlaybackRate(a){const b=this.getState();if(b===mO||b===mN||b===nN){try{webapis.avplay.setSpeed(a),
this.F=a}catch(c){return this.g.debug("Error while trying to set playback rate",c),this.setPlaybackRate(this.F)}return!0}this.g.debug("Cannot set playback rate; AVPlay is in inconsistent state: "+b);return!1}getPlaybackRate(){return this.F}load(a,b){const c=this;return _.x(function*(){c.g.debug("configure()",b||"");try{yield aO(c),yield hO(c,a,b)}catch(d){throw new _.I(_.G,7,7003,null,d);}})}getState(){if(this.f&&this.a)return this.a.Hf;try{return webapis.avplay.getState()}catch(a){this.B(JSON.stringify(a))}}seek(a){const b=
1E3*a;return new Promise((c,d)=>{this.C=!0;this.m.trigger(new _.F(_.jg));webapis.avplay.seekTo(b,()=>{this.C=!1;this.m.trigger(new _.F(_.ig));c()},()=>{this.C=!1;d()})})}getPosition(){if(this.f&&this.a)return this.a.position;try{return webapis.avplay.getCurrentTime()/1E3}catch(a){this.B(JSON.stringify(a))}}getDuration(){if(this.f&&this.a)return this.a.duration;try{return webapis.avplay.getDuration()/1E3}catch(a){this.B(JSON.stringify(a))}}release(){return new Promise((a,b)=>{try{this.h&&(this.h.release(),
this.h=null);webapis.avplay.stop();webapis.avplay.close();for(const c in this.j){const d=this.j[c];d&&d.pe.stop()}this.j={};this.F=1;this.C=!1;this.a=this.l=null;return a()}catch(c){return b(c)}})}getVolume(){let a=null;try{a=tizen.tvaudiocontrol.getVolume()}catch(b){switch(b.name){case YM:this.g.debug("The application does not have the privilege to get the volume.",ZM);break;default:this.g.debug(WM,b)}}return a}setVolume(a){try{tizen.tvaudiocontrol.setVolume(Math.max(0,Math.min(100*a,100)))}catch(b){switch(b.name){case "InvalidValueError":this.g.warn("Invalid value passed for setVolume.",
"The passed value value should be in the range of 0 to 1.");break;case YM:this.g.warn("The application does not have the privilege to set the volume.",ZM);break;default:this.g.warn("An unknown error occurred while trying to set volume",b)}}}isLive(){if(this.f&&this.a)return this.a.isLive;try{return"1"===webapis.avplay.getStreamingProperty("IS_LIVE")}catch(a){this.B(JSON.stringify(a))}}stop(){try{webapis.avplay.stop()}catch(a){this.g.debug(a)}}getDrmInfo(){this.h&&this.h.getDrmInfo();return null}setSourceIndex(a){this.G=
a}getSourceIndex(){return this.G}getLoadedSource(){return this.l&&this.l[this.getSourceIndex()]}},nO="IDLE",mO="READY",mN="PLAYING",nN="PAUSED",CN=_.Bb,DN=_.rB,MN="TEXT",rO="PLAYER_MSG_RESOLUTION_CHANGED",qO="PLAYER_MSG_BITRATE_CHANGE",jN="PLAYREADY",eN="WIDEVINE_CDM";var BO=class extends _.su{constructor(){super();this.a=new xO(this);this.f=new oO(this);this.configuration=this.B=_.rl();this.w=null;this.g=new _.S("clpp.tizen.Player");this.j=null;this.l=new tO;this.C=new _.zr;this.o=this.h=null;this.A=!1}I(){this.g.debug("On Stream completed. Current time: ",this.getPosition());this.trigger(new _.F(_.Sd));this.configuration.loop?this.seek(this.configuration.startTime||0).catch(()=>{this.g.debug("Could not loop playback")}):this.a.stop()}F(a){this.trigger(new _.F(_.Zf,
{currentTime:a.currentTime/1E3}))}J(a){const b=this.a.getPosition(),c=b+a.duration/1E3;let d=a.text||"";this.g.debug("Got subtitles: ",d,"start:",b,"end:",c,a);(d=_.gj(d))&&this.o.append([new _.Vt(b,c,d)],[])}G(a){this.g.debug("DRM event: "+a.drmType+", data: "+a.drmData)}K(){this.A||(this.g.debug("Initial buffering completed..."),this.A=!0)}H(a){this.g.debug(`Error: TYPE: ${a.eventType}`);lN(this.f,_.Mo);a=new _.I(_.G,7,7200,{tizenerror:a.eventType});this.a.release();this.trigger(new _.F(_.q,{detail:a}))}init(a,
b){this.configuration=this.B=b;this.w=a;this.a.on(lO,this.I,this);this.a.on(UN,this.F,this);this.a.on(uO,this.J,this);this.a.on(vO,this.G,this);this.a.on(wO,this.H,this);this.a.on(kO,this.K,this);this.f.initialize();this.l.initialize(this);this.g.debug("Initializing player surface");this.w.hideMediaElement();a=yO;yO+=1;a="__clpp_tizen_player_"+a;this.j=_.op(_.Ce,{id:a,type:"application/avplayer"});this.w.addElementToContainer(this.j,!0);var c=this.w.getMedia();if(c){a=this.j;{b=[_.Fg,_.Zd,"position",
_.ee,"top"];const e={};c=null!==c.parentElement?window.getComputedStyle(c,null):c.style;if(!b||0===b.length)for(d in b||(b=[]),c)b.push(d);for(const f of b)e[f]=c[f];var d=e}_.qp(a,d);iO(this)}}getSurface(){return this.w}getConfiguration(){return this.configuration}getTimeline(){return null}setupPlaylist(){return Promise.reject(_.Za)}appendLoad(){return Promise.reject(_.Za)}seekWith(){return Promise.reject(_.Za)}setSeekInterceptor(){}setPlaybackSessionId(){}getBandwidthEstimate(){return null}destroy(){const a=
this;return _.x(function*(){yield a.release();a.a.off(lO,a.I);a.a.off(UN,a.F);a.a.off(uO,a.J);a.a.off(vO,a.G);a.a.off(wO,a.H);a.a.off(kO,a.K);a.h&&(yield a.h.destroy(),a.h=null);a.j&&(a.j.parentElement.removeChild(a.j),a.j=null);a.l.destroy();a.f.destroy();a.l=null;a.f=null})}namespace(){return zO}getPlaybackRate(){return this.a.getPlaybackRate()}setDrmCustomDataModifier(){}setCdnErrorCallback(){}detach(){}setPlaybackRate(a){this.a.setPlaybackRate(a)}getPosition(){return this.getMediaPosition()}getMediaPosition(){return 0<
(this.configuration.startTime||0)&&!this.A?0:this.f.getState()===_.Lo?this.getDuration():this.a.getPosition()||0}seek(a){return typeof a===_.t&&0<=a?(this.isLive()||(a=Math.min(a,this.getDuration())),this.a.seek(a)):Promise.reject()}getPresentationStartTime(){return null}getSeekRange(){return{start:0,end:0}}getVolume(){const a=this.a.getVolume();return typeof a===_.t?a/100:null}setVolume(a){this.a.setVolume(a)}getDuration(){return this.getMediaDuration()}getMediaDuration(){return this.a.getDuration()}getBufferInfo(){this.g.warn(_.pa);
return new _.ru}getTrackManager(){return this.l}unload(){return this.a.release().then(()=>{this.l.release()})}release(){const a=this;return _.x(function*(){a.h&&(yield a.h.release());a.o&&(yield a.o.destroy(),a.o=null);yield a.a.release();a.l.release();a.f.release();a.A=!1})}load(a){const b=this;return _.x(function*(){b.configuration=_.tl(b.B,a);var c=_.Do(b.configuration,[_.ae,"native"]);b.o=c.create(b);c=_.Zo(b.configuration)[0];if(b.configuration.tizen&&b.configuration.tizen.sideStreamText){b.h=
new pO;b.h.initialize(b);try{yield b.h.load(c),b.h.start()}catch(d){b.g.error(d)}}try{yield b.a.load(b.configuration)}catch(d){throw b.onError(d),d;}b.l.load()})}play(){this.trigger(new _.F(_.Re));iO(this);return this.a.play().then(()=>{oN(this.f)})}pause(){return this.a.pause().then(()=>{oN(this.f)})}getState(){return this.f.getState()}getPeriods(){return[]}onError(a){const b=new _.F(_.q,{detail:a});a.severity===_.G&&(lN(this.f,_.Mo),this.a.release());this.trigger(b);b.defaultPrevented&&(b.a=!0)}getDrmInfo(){return this.a.getDrmInfo()}isEnded(){return this.f.getState()===
_.Lo}isPaused(){return this.a.getState()===nN}isMuted(){return ZN(this.a)}setMuted(a){cO(this.a,a)}getNetworkEngine(){return this.C}setNetworkEngine(a){this.C=a}setCmsdManager(){}isLive(){return this.a.isLive()}getStats(){return null}setSourceIndex(a){this.a.setSourceIndex(a)}getSourceIndex(){return this.a.getSourceIndex()}getLoadedSource(){return this.a.getLoadedSource()}canPlay(a,b){return(new AO).canPlay(a,b)}getTimelineCues(){return[]}getCueTimeline(){return null}getTextDisplayer(){return this.o}resetAbr(){}},
zO="clpp.tizen",yO=0,AO=class{a(){return zO}canPlay(a){a=a.type;const b=!!window.webapis;if((a===_.tc||a===_.kl||a===_.yc)&&b){if(_.vk(2))return 2;if(_.vk(3)||_.vk(4)||_.vk(5)||_.vk(6))return _.C("Use of clpp.tizen.TizenComponent is not recommended for Tizen version \x3e\x3d 3."),1}return 0}f(a){return a===_.ma}create(){return new BO}};_.z("clpp.tizen.TizenComponent",class extends _.Av{f(){_.uh(new AO)}a(){var a=zO;a&&_.sh[a]&&(delete _.sh[a],_.th.info("Removed Player factory: '"+a+"'"))}id(){return"tizen"}});var dO="onbufferingstart",jO="onbufferingprogress",kO="onbufferingcomplete",lO="onstreamcompleted",UN="oncurrentplaytime",sO="onevent",uO="onsubtitlechange",vO="ondrmevent",wO="onerror",fO="preparingstart",gO="preparingend";};f.call(g, window);