goldfire / howler.js

Javascript audio library for the modern web.
https://howlerjs.com
MIT License
23.91k stars 2.23k forks source link

How to force Web Audio API -- don't allow fallback to HTML5? #1278

Open chadananda opened 4 years ago

chadananda commented 4 years ago

I'm cutting my audio up into sprites for precision manipulation in a way that will not work at all with HTML5 Audio. I need to force Web Audio Api only. I've noticed on some devices (android w/ chrome) that Howler seems to slip back to HTML5, mangling playback completely.

I'm not sure why Howler seems to be falling back to HTML5 sometimes but I need it to stop. How can I detect when this happens and then why?

chadananda commented 4 years ago

Found howl._webAudio which is a big help.

chadananda commented 4 years ago

It would be helpful to throw some console error when falling back to html5, preferably with a reason so it can be fixed.

chadananda commented 4 years ago

Seems like Howler starts out with Web Audio API then switches right back to HTML5 the very first time any network glitch comes along -- basically killing any app that cannot use HTML5. And there seems no way to switch it back.

chadananda commented 4 years ago

It would be great to have a configuration option to disable HTML5 audio.

For some applications HTML5 audio does not work at all, and Howler's eagerness to switch to HTML5 audio at the slightest provocation just breaks the app.

shahburhan commented 4 years ago

You actually can set it to use just the Audio Api. You need to set the html5 property to false on the howl instance and voila.

chadananda commented 4 years ago

That is not correct. False is the default value. Howler allows you to exclude WebAudio with true but when it is set to false Howler will switch back to true if anything at all goes wrong -- instead of throwing an error. It does not seem possible to exclude HTML5 in Howler.

For example, line 2363 of howler.core.js

      xhr.onerror = function() {
        // If there is an error, switch to HTML5 Audio.
        if (self._webAudio) {
          self._html5 = true;
          self._webAudio = false;
          self._sounds = [];
          delete cache[url];
          self.load();
        }
      };
chadananda commented 4 years ago

It would be nice to have an option to simply throw an error if something goes wrong -- instead of assuming we can switch back to HTML5 audio.

Ideally there would be an allowHTML5fallback option with default true so HTML5 audio could be forced off when the application simply can not support HTML5 audio.

shahburhan commented 4 years ago

That is correct, there should be something like that out of the box. But may be until that's there, we can watch for the switch and when it happens, the audio can be forced off and an error can be flagged.