Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

226
Visualizações
How to write hls.js loader?

I'm trying to make new loader for hls.js fragments, but it does not work.

Made everything by their doc (https://github.com/video-dev/hls.js/blob/master/docs/API.md#loader).

Why it's not working?

const Loader = class {

      start = Date.now();

      stats: LoadStats = {
        aborted: false,
        loaded: 0,
        retry: 0,
        total: 0,
        chunkCount: 0,
        bwEstimate: 0,
        loading: { start: this.start, first: 0, end: 0 },
        parsing: { start: this.start, end: 0 },
        buffering: { start: this.start, first: 0, end: 0 },
      };

      // @ts-ignore
      load = async (context, config, callbacks) => {

        const request = new XMLHttpRequest();

        request.open('GET', context.url, true);
        request.responseType = context.responseType;

        request.onprogress = (event: ProgressEvent) => {
          const now = Date.now();

          this.stats.loaded = event.loaded;
          this.stats.total = event.total;
          this.stats.chunkCount += 1;
          this.stats.bwEstimate = this.stats.loaded / (now - this.start);

          if (this.stats.loading.first === 0) {
            this.stats.loading.first = now;
            this.stats.buffering.first = now;
          }

          // There is no ArrayBuffer in response, XHR does not support that
          callbacks.onProgress(this.stats, context, new ArrayBuffer(0));
        };

        request.onabort = () => {
          this.stats.aborted = true;

          callbacks.onError(
            {
              code: 0,
              text: 'Error while loading of the fragment',
            },
            context,
            request
          );
        };

        request.onreadystatechange = () => {
          if (request.readyState !== 4) {
            return;
          }

          const now = Date.now();

          this.stats.loaded = request.response.byteLength;
          this.stats.total = request.response.byteLength;

          this.stats.loading.end = now;
          this.stats.parsing.end = now;
          this.stats.buffering.end = now;

          callbacks.onSuccess(
            {
              url: request.responseURL,
              data: request.response,
            },
            this.stats,
            context,
            request
          );
        };

        request.send();
      };

      /** Abort any loading in progress. */
      abort = function (): void {};

      /** Destroy loading context. */
      destroy = function (): void {};
    };

Log has a weird thing – hls.js loading all segments, one by one, from 1st to 21st, but do not buffer them, i.e. I can't play video, there is an infinite loader.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda