Is there a way to indicate audio download progress/buffer when using Howler.js?
Asked Answered
A

1

7

I'm using Howler.js and trying to accomplish something like this:

download with buffer

However, Howler doesn't seem to have support for audio "progress" events. Anybody know how I could work around this?

Ashkhabad answered 11/6, 2016 at 23:59 Comment(1)
Any resolve to this issue?Ninanincompoop
P
8

You'll need to bind to Howler's non-public API to achieve this, at least until this feature is implemented (if ever).

const audio = new Howl({
  src: 'https://howlerjs.com/assets/howler.js/examples/player/audio/rave_digger.webm',
  html5: true,
  preload: false,
});

const handleLoad = () => {
  const node = audio._sounds[0]._node;
  // const node:HTMLAudioElement = (audio as any)._sounds[0]._node; // For Typescript
  node.addEventListener('progress', () => {
    const duration = audio.duration();

    // https://developer.mozilla.org/en-US/Apps/Fundamentals/Audio_and_video_delivery/buffering_seeking_time_ranges#Creating_our_own_Buffering_Feedback
    if (duration > 0) {
      for (let i = 0; i < node.buffered.length; i++) {
        if (node.buffered.start(node.buffered.length - 1 - i) < node.currentTime) {
          const bufferProgress = (node.buffered.end(node.buffered.length - 1 - i) / duration) * 100;
          // do what you will with it. I.E - store.set({ bufferProgress });
          break;
        }
      }
    }
  }
};

audio.on('load', handleLoad);

Original answer can be found here in goldfire/howler.js

Pulmonate answered 6/1, 2019 at 15:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.