import{P as PrestoPlayer}from"./presto-player.presto-playlist-item.presto-playlist-overlay.presto-playlist-ui-49967e08.js";import"./index-56b61ec5.js";import"./cache-cues-d738e7c8.js";const loadHLS=({config:e,selector:t,src:o,preload:r})=>new Promise((async(n,a)=>{if(!window.Hls)for(;!window.hasOwnProperty("Hls");)await new Promise((e=>setTimeout(e,50)));if(window.Hls.isSupported()){let a=!["metadata","none"].includes(r);wp?.blocks&&(a=!0);var l=new window.Hls(window?.wp?.hooks?.applyFilters?.("presto.hlsSettings",{autoStartLoad:a,capLevelToPlayerSize:!0}));return l.loadSource(o),l.on(window.Hls.Events.LEVEL_SWITCHED,((e,o)=>{var r=t.closest(".presto-player__wrapper").querySelector(".plyr__menu__container [data-plyr='quality'][value='0'] span");l.autoLevelEnabled?r.innerHTML=`AUTO (${l.levels[o.level].height}p)`:r.innerHTML="AUTO"})),void l.on(window.Hls.Events.MANIFEST_PARSED,(function(o,r){var a=l.levels.map((function(e){return e.height}));a.unshift(0);const s=(a||[]).findIndex((e=>e===parseInt(window?.prestoPlayer?.hls_start_level)));l.startLevel=s?s-1:2,e.quality={default:0,options:a,forced:!0,onChange:function(e){0===e?prestoHLS.currentLevel=-1:prestoHLS.levels.forEach((function(t,o){t.height===e&&(console.log("Found quality match with "+e),prestoHLS.currentLevel=o)}))}},l.attachMedia(t),window.prestoHLS=l;const i=new PrestoPlayer(t,{...e});i.hls=l;const p=()=>{l.startLoad(-1),i.off("waiting",p)};return i.on("waiting",p),i.on("languagechange",(()=>{setTimeout((()=>l.subtitleTrack=i.currentTrack),50)})),n(i)}))}return t.canPlayType("application/vnd.apple.mpegurl"),n(new PrestoPlayer(t,{...e}))}));export{loadHLS as default};