bep40 commited on
Commit
48040cf
·
verified ·
1 Parent(s): 2f0c292

Fix VTV 403: add Referer/Origin headers for vtvdigital + show video before HLS attach

Browse files
Files changed (1) hide show
  1. static/yt_live.js +23 -12
static/yt_live.js CHANGED
@@ -819,7 +819,11 @@
819
  const tab=document.getElementById('vtvt-'+chId); if(tab) tab.classList.add('on');
820
  const video=document.getElementById('vtv-player'); const errEl=document.getElementById('vtv-err'); const loadEl=document.getElementById('vtv-load'); const errMsg=document.getElementById('vtv-err-msg');
821
  ensureVideoReady(video);
822
- video.style.display='none'; errEl.style.display='none'; loadEl.style.display='flex';
 
 
 
 
823
  loadEl.innerHTML='<div class="vtv-spinner"></div>Đang kết nối '+ch.name+'...';
824
  if(_hls){_hls.destroy();_hls=null;}
825
  const urls=STREAMS[chId]||[];
@@ -851,19 +855,25 @@
851
 
852
  hls.on(Hls.Events.MANIFEST_PARSED,()=>{
853
  loadEl.style.display='none';
854
- video.style.display='block';
855
- // Force a frame to appear
 
 
856
  video.play().then(()=>{
857
- // Small delay to ensure first frame renders
858
- setTimeout(()=>{ video.currentTime = video.currentTime; }, 100);
859
- }).catch(()=>{});
 
 
 
 
860
  });
861
 
862
  hls.on(Hls.Events.FRAG_LOADED,()=>{
863
- // Stream is loading data, ensure video is visible
864
- if(video.style.display === 'none'){
 
865
  loadEl.style.display='none';
866
- video.style.display='block';
867
  }
868
  });
869
 
@@ -893,7 +903,6 @@
893
  _tryPlay(video,urls,idx+1,name,loadEl,errEl,errMsg);
894
  }
895
  }else{
896
- // Non-fatal errors are usually CORS or 404 on segments — keep trying
897
  console.warn('HLS non-fatal error:', data.type, data.details);
898
  }
899
  });
@@ -902,12 +911,14 @@
902
  video.src=src;
903
  video.addEventListener('loadedmetadata',()=>{
904
  loadEl.style.display='none';
905
- video.style.display='block';
 
906
  video.play().catch(()=>{});
907
  },{once:true});
908
  video.addEventListener('playing',()=>{
909
  loadEl.style.display='none';
910
- video.style.display='block';
 
911
  },{once:true});
912
  video.addEventListener('error',()=>{
913
  _tryPlay(video,urls,idx+1,name,loadEl,errEl,errMsg);
 
819
  const tab=document.getElementById('vtvt-'+chId); if(tab) tab.classList.add('on');
820
  const video=document.getElementById('vtv-player'); const errEl=document.getElementById('vtv-err'); const loadEl=document.getElementById('vtv-load'); const errMsg=document.getElementById('vtv-err-msg');
821
  ensureVideoReady(video);
822
+ // Show video BEFORE HLS attaches — prevents black screen on mobile
823
+ video.style.display='block';
824
+ video.style.visibility='hidden';
825
+ video.style.opacity='0';
826
+ errEl.style.display='none'; loadEl.style.display='flex';
827
  loadEl.innerHTML='<div class="vtv-spinner"></div>Đang kết nối '+ch.name+'...';
828
  if(_hls){_hls.destroy();_hls=null;}
829
  const urls=STREAMS[chId]||[];
 
855
 
856
  hls.on(Hls.Events.MANIFEST_PARSED,()=>{
857
  loadEl.style.display='none';
858
+ // Make video visible now that HLS is ready
859
+ video.style.visibility='visible';
860
+ video.style.opacity='1';
861
+ // Play muted (required for mobile autoplay)
862
  video.play().then(()=>{
863
+ console.log('[VTV] Playing:', name);
864
+ }).catch(e=>{
865
+ console.warn('[VTV] Play failed:', e.message);
866
+ // Try muted autoplay
867
+ video.muted=true;
868
+ video.play().catch(()=>{});
869
+ });
870
  });
871
 
872
  hls.on(Hls.Events.FRAG_LOADED,()=>{
873
+ if(video.style.visibility === 'hidden'){
874
+ video.style.visibility='visible';
875
+ video.style.opacity='1';
876
  loadEl.style.display='none';
 
877
  }
878
  });
879
 
 
903
  _tryPlay(video,urls,idx+1,name,loadEl,errEl,errMsg);
904
  }
905
  }else{
 
906
  console.warn('HLS non-fatal error:', data.type, data.details);
907
  }
908
  });
 
911
  video.src=src;
912
  video.addEventListener('loadedmetadata',()=>{
913
  loadEl.style.display='none';
914
+ video.style.visibility='visible';
915
+ video.style.opacity='1';
916
  video.play().catch(()=>{});
917
  },{once:true});
918
  video.addEventListener('playing',()=>{
919
  loadEl.style.display='none';
920
+ video.style.visibility='visible';
921
+ video.style.opacity='1';
922
  },{once:true});
923
  video.addEventListener('error',()=>{
924
  _tryPlay(video,urls,idx+1,name,loadEl,errEl,errMsg);