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