简体   繁体   English

HLS stream HTML5 视频 - 缓冲 X 时间后刷新

[英]HLS stream HTML5 video - refresh after buffering for X time

I have a simple site with an HLS stream from a m3u8 playlist in an autoplay video tag.我有一个简单的站点,其中包含来自自动播放视频标签中 m3u8 播放列表的 HLS stream。 If the stream stops for more than 10s or so it will not "catch up" and start again when the stream is restarted - I need to manually refresh the page to get it to play again.如果 stream 停止超过 10 秒左右,它不会“赶上”并在 stream 重新启动时重新开始 - 我需要手动刷新页面以使其再次播放。

Is there a way with js (or something else) to automatically refresh the page after the video has been buffering for X time?有没有办法用js(或其他东西)在视频缓冲X时间后自动刷新页面? (say 5 seconds) (比如说 5 秒)

I managed to get this with some help from VC.One's answer.在 VC.One 的回答的帮助下,我设法得到了这个。 This will reload after the video has been buffering for 5 seconds, if the video was previously playing.如果视频之前正在播放,这将在视频缓冲 5 秒后重新加载。 Otherwise it will be stuck in a reload loop if it never starts playing.否则,如果它从不开始播放,它将卡在重新加载循环中。 I am still looking for a way to check whether the stream is live without actually reloading the page.我仍在寻找一种方法来检查 stream 是否处于活动状态,而无需实际重新加载页面。 video.load() and video.play() are giving me errors, but I will update this post when I figure it out. video.load()video.play()给了我错误,但是当我弄清楚时我会更新这篇文章。

var reloadCheck;
var reloadThisTime;
var video = document.getElementById("videotag");
var sourcetag = document.getElementById("sourcetag");
video.addEventListener('waiting', (event) => {
  console.log("No connection");
  reloadCheck = setTimeout(function(){
    if(reloadThisTime){
      location = '';
    };
  },5000);
});

video.addEventListener('playing', (event) => {
  console.log("Connected");
  clearTimeout(reloadCheck);
  reloadThisTime = true;
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM