1/** 2 * Shared HLS playback for PDP product-image and Quick View (single place for init/teardown). 3 * Lazy-loads hls.js on first Chrome/Firefox play. Safari uses native HLS â never downloads hls.js. 4 * Stores instance on videoEl._hlsInstance. 5 */ 6(function (global) { 7 'use strict'; 8 9 var INSTANCE_KEY = '_hlsInstance'; 10 var hlsLibPromise = null; 11 12 function getHlsCdnUrl() { 13 var cfg = global.wizHlsLib || {}; 14 return cfg.url || ''; 15 } 16 17 function loadHlsLib() { 18 if (typeof global.Hls !== 'undefined') { 19 return Promise.resolve(); 20 } 21 if (!hlsLibPromise) { 22 hlsLibPromise = new Promise(function (resolve, reject) { 23 var cdnUrl = getHlsCdnUrl(); 24 if (!cdnUrl) { 25 reject(new Error('hls.js CDN URL not configured')); 26 return; 27 } 28 var existing = document.querySelector('script[data-wiz-hls-lib="1"]'); 29 if (existing) { 30 existing.addEventListener('load', function () { resolve(); }, { once: true }); 31 existing.addEventListener('error', reject, { once: true }); 32 return; 33 } 34 var script = document.createElement('script'); 35 script.src = cdnUrl; 36 script.defer = true; 37 script.setAttribute('data-wiz-hls-lib', '1'); 38 script.onload = function () { resolve(); }; 39 script.onerror = reject; 40 document.head.appendChild(script); 41 }); 42 } 43 return hlsLibPromise; 44 } 45 46 function canUseNativeHls(videoEl) { 47 return !!(videoEl && videoEl.canPlayType && videoEl.canPlayType('application/vnd.apple.mpegurl')); 48 } 49 50 function playVideo(videoEl) { 51 void videoEl.play().catch(function () {}); 52 } 53 54 function attachNative(videoEl, hlsSrc) { 55 if (videoEl.src !== hlsSrc) { 56 videoEl.src = hlsSrc; 57 } 58 playVideo(videoEl); 59 } 60 61 function attachHlsJs(videoEl, hlsSrc) { 62 if (videoEl[INSTANCE_KEY]) { 63 playVideo(videoEl); 64 return; 65 } 66 var hls = new global.Hls({ enableWorker: true }); 67 hls.loadSource(hlsSrc); 68 hls.attachMedia(videoEl); 69 hls.on(global.Hls.Events.MANIFEST_PARSED, function () { playVideo(videoEl); }); 70 videoEl[INSTANCE_KEY] = hls; 71 } 72 73 function initAndPlay(videoEl, hlsSrc) { 74 if (!videoEl || !hlsSrc) { 75 return Promise.resolve(); 76 } 77 // Safari / iOS play HLS natively â skip downloading/parsing hls.js (large TBT cost). 78 if (canUseNativeHls(videoEl) && (typeof global.Hls === 'undefined' || !global.Hls.isSupported())) { 79 attachNative(videoEl, hlsSrc); 80 return Promise.resolve(); 81 } 82 if (typeof global.Hls !== 'undefined' && global.Hls.isSupported()) { 83 attachHlsJs(videoEl, hlsSrc); 84 return Promise.resolve(); 85 } 86 return loadHlsLib().then(function () { 87 if (typeof global.Hls !== 'undefined' && global.Hls.isSupported()) { 88 attachHlsJs(videoEl, hlsSrc); 89 return; 90 } 91 if (canUseNativeHls(videoEl)) { 92 attachNative(videoEl, hlsSrc); 93 } 94 }); 95 } 96 97 function destroy(videoEl) { 98 if (!videoEl || !videoEl[INSTANCE_KEY]) { 99 return; 100 } 101 try { 102 videoEl[INSTANCE_KEY].destroy(); 103 } catch (e) {} 104 videoEl[INSTANCE_KEY] = null; 105 } 106 107 /** Pause, destroy HLS, clear src â use when hiding the player (e.g. Quick View). */ 108 function reset(videoEl) { 109 if (!videoEl) { 110 return; 111 } 112 try { 113 videoEl.pause(); 114 } catch (e) {} 115 destroy(videoEl); 116 videoEl.removeAttribute('src'); 117 videoEl.querySelectorAll('source').forEach(function (s) { 118 s.remove(); 119 }); 120 videoEl.load(); 121 } 122 123 global.WizHlsVideo = { 124 ensureReady: loadHlsLib, 125 initAndPlay: initAndPlay, 126 destroy: destroy, 127 reset: reset 128 }; 129})(typeof window !== 'undefined' ? window : this);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.