ntdservices commited on
Commit
6911fda
·
verified ·
1 Parent(s): 708b0c0

Update static/index.html

Browse files
Files changed (1) hide show
  1. static/index.html +49 -37
static/index.html CHANGED
@@ -421,43 +421,55 @@
421
  const wrap = document.createElement('div');
422
  wrap.className = 'media';
423
 
424
- if (it.type === 'video') {
425
- wrap.setAttribute('data-kind','video'); // reserve space
426
-
427
- const v = document.createElement('video');
428
- // No controls; looped; autoplay; muted for autoplay to work; inline for mobile
429
- v.autoplay = true; v.loop = true; v.muted = true; v.playsInline = true;
430
- v.crossOrigin = 'anonymous';
431
- v.style.width = '100%'; v.style.height = 'auto';
432
-
433
- if (window.Hls && window.Hls.isSupported() && /\.m3u8($|\?)/i.test(it.src)) {
434
- const hls = new Hls();
435
- hls.loadSource(it.src);
436
- hls.attachMedia(v);
437
- hls.on(Hls.Events.MANIFEST_PARSED, () => { v.play().catch(()=>{}); });
438
- } else {
439
- const srcEl = document.createElement('source');
440
- srcEl.src = it.src;
441
- const mime = guessVideoMime(it.src); if (mime) srcEl.type = mime;
442
- v.appendChild(srcEl);
443
- v.load();
444
- v.play().catch(()=>{});
445
- }
446
-
447
- v.addEventListener('loadedmetadata', () => {
448
- if (v.videoWidth && v.videoHeight) wrap.style.aspectRatio = (v.videoWidth / v.videoHeight).toString();
449
- });
450
- v.addEventListener('error', () => {
451
- const note = document.createElement('div');
452
- note.style.padding = '10px 12px';
453
- note.style.color = '#ffd2d2';
454
- note.textContent = 'Video failed to load. Use MP4 (H.264/AAC), WEBM, or HLS (.m3u8).';
455
- wrap.innerHTML = ''; wrap.appendChild(note);
456
- }, {once:true});
457
-
458
- wrap.appendChild(v);
459
- // Clicking video should NOT close; user may tap it; it loops anyway.
460
- } else {
 
 
 
 
 
 
 
 
 
 
 
 
461
  const img = document.createElement('img');
462
  img.src = it.src; img.alt = it.title || '';
463
  // Click image to close that popup
 
421
  const wrap = document.createElement('div');
422
  wrap.className = 'media';
423
 
424
+ if (it.type === 'video') {
425
+ wrap.setAttribute('data-kind','video'); // reserve space
426
+
427
+ const v = document.createElement('video');
428
+ v.autoplay = true; v.loop = true; v.muted = true; v.playsInline = true;
429
+ v.crossOrigin = 'anonymous';
430
+ v.style.width = '100%'; v.style.height = 'auto';
431
+
432
+ let hlsInst = null;
433
+ if (window.Hls && window.Hls.isSupported() && /\.m3u8($|\?)/i.test(it.src)) {
434
+ hlsInst = new Hls();
435
+ hlsInst.loadSource(it.src);
436
+ hlsInst.attachMedia(v);
437
+ hlsInst.on(Hls.Events.MANIFEST_PARSED, () => { v.play().catch(()=>{}); });
438
+ } else {
439
+ const srcEl = document.createElement('source');
440
+ srcEl.src = it.src;
441
+ const mime = guessVideoMime(it.src); if (mime) srcEl.type = mime;
442
+ v.appendChild(srcEl);
443
+ v.load();
444
+ v.play().catch(()=>{});
445
+ }
446
+
447
+ v.addEventListener('loadedmetadata', () => {
448
+ if (v.videoWidth && v.videoHeight) wrap.style.aspectRatio = (v.videoWidth / v.videoHeight).toString();
449
+ });
450
+
451
+ // CLOSE THIS POPUP when user clicks the small video
452
+ const closeSelf = (e) => {
453
+ e.stopPropagation();
454
+ it.open = false;
455
+ try { v.pause(); } catch {}
456
+ if (hlsInst) { try { hlsInst.destroy(); } catch {} }
457
+ renderItems();
458
+ };
459
+ // Click anywhere on the video area to close
460
+ wrap.addEventListener('click', closeSelf);
461
+ v.addEventListener('click', closeSelf);
462
+
463
+ v.addEventListener('error', () => {
464
+ const note = document.createElement('div');
465
+ note.style.padding = '10px 12px';
466
+ note.style.color = '#ffd2d2';
467
+ note.textContent = 'Video failed to load. Use MP4 (H.264/AAC), WEBM, or HLS (.m3u8).';
468
+ wrap.innerHTML = ''; wrap.appendChild(note);
469
+ }, {once:true});
470
+
471
+ wrap.appendChild(v);
472
+ } else {
473
  const img = document.createElement('img');
474
  img.src = it.src; img.alt = it.title || '';
475
  // Click image to close that popup