1 line
1.2 KiB
JavaScript
1 line
1.2 KiB
JavaScript
document.addEventListener("DOMContentLoaded",(function(){const e=document.querySelectorAll("video");0!==e.length&&e.forEach((function(e){const o=Array.from(e.querySelectorAll("source")).find((e=>e.src.includes(".m3u8")));if(o&&!function(){const e=document.createElement("video");return e.canPlayType("application/vnd.apple.mpegURL")||e.canPlayType("application/x-mpegURL")}())if("undefined"!=typeof Hls)if(Hls.isSupported()){const r=new Hls({maxBufferLength:30,maxMaxBufferLength:60});r.loadSource(o.src),r.attachMedia(e),r.on(Hls.Events.MANIFEST_PARSED,(function(){e.autoplay&&e.play().catch((e=>console.warn("Auto-play failed:",e)))})),r.on(Hls.Events.ERROR,(function(o,n){if(console.warn("HLS error:",n),n.fatal)switch(n.type){case Hls.ErrorTypes.NETWORK_ERROR:console.log("Fatal network error, trying to recover..."),r.startLoad();break;case Hls.ErrorTypes.MEDIA_ERROR:console.log("Fatal media error, trying to recover..."),r.recoverMediaError();break;default:r.destroy();const o=Array.from(e.querySelectorAll("source")).find((e=>"video/mp4"===e.type));o&&(e.src=o.src)}}))}else console.warn("HLS.js is not supported in this browser");else console.warn("HLS.js is not loaded")}))})); |