Giter Site home page Giter Site logo

Comments (4)

matb33 avatar matb33 commented on August 19, 2024

Below is a hack temporary solution until @mangui has time to implement the above. I emphasize that this is a hack solution -- it works but you need to wait until the looping error event is fired before it recovers, so it's generally slow. It doesn't hurt to keep once the proper drift solution is implemented, as it offers a fallback recovery in case the looping crops up for other potential reasons:

var hls = new Hls();
var video = document.getElementById('your-video-id');

hls.attachVideo(video);

//...

hls.on(Hls.Events.ERROR, function (event, data) {
  if (!data.fatal && data.details === Hls.ErrorDetails.FRAG_LOOP_LOADING_ERROR) {
    seekToNearestBuffered();
  }
});

function seekToNearestBuffered() {
  var pos = video.currentTime,
    closest = null,
    smallestDiff = null,
    start, diff;

  console.log("[hlsjs] attempt to seek to nearest buffered area, currentTime:", pos);

  for (var i = 0; i < video.buffered.length; i++) {
    start = video.buffered.start(i);
    diff = Math.abs(pos - start);
    if (smallestDiff === null || diff < smallestDiff) {
      closest = start;
      smallestDiff = diff;
    }
  }

  if (closest !== null) {
    console.log("[hlsjs] seeking to closest buffered area start:", closest);
    video.currentTime = closest;
  }
}

from hls.js.

mangui avatar mangui commented on August 19, 2024

@matb33 your playlist should work, you can check on drift_refactor branch
@shacharz it should also fix the playback of https://livestream.peer5.com/video/soccer/index.m3u8

from hls.js.

mangui avatar mangui commented on August 19, 2024

closing as implemented

from hls.js.

matb33 avatar matb33 commented on August 19, 2024

So far this drift fix has been working great. We're running it through a beta period with several users and will let you know if we encounter issues.

from hls.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.