Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creates a pool of activated HTML5 Audio objects for use on mobile. #1008

Merged
merged 1 commit into from
Dec 8, 2018

Conversation

scottanderson42
Copy link
Contributor

Currently the WebAudio API is unlocked via user interaction in the _enableMobileAudio method. This does not however unlock HTML5 Audio as well. Since HTML5 Audio objects must be individually unlocked, using them without user interaction can be accomplished by pooling a number of activated Audio objects at the same time WebAudio is unlocked, and using those pooled objects whenever a new sound is requested.

Changes:

  • Adds a private mobile audio pool to the Howler object.
  • Adds a new Howler global configuration named "mobileHtml5AudioPoolDefaultSize" that governs the number of pooled Audio objects, with a starting value of 10.
  • Fill the pool in _enableMobileAudio().
  • Use Audio objects from the pool when a Sound object is created in HTML5 mode.
  • An over-scheduled pool can be configured via the Howler.shouldMobileHtml5AudioPoolErrorWhenEmpty option to still return Audio objects, however they are not guaranteed to be unlocked. This option defaults to 'false'.

@gugiserman
Copy link

@scottanderson42 I couldn't get it to work on my case (from issue #1031). Any ideas why? All I did was to simply turn on the new feature.

Also, when I first tried to import Howler from your PR, I had to fix the following missing () in if statements:

@LukeWalsh
Copy link

It looks like using HTML5 audio on iOS is currently broken but this change would fix it. This is important because falling back to HTML5 is necessary for many reasons, one of which is adjusting audio playback rate while holding pitch constant (which is not possible via Web Audio).

@scottanderson42 do you have time to address @gugiserman's syntax corrections?

If not I can open a new pull request as I need to use this pooling unlock feature :).

Currently the WebAudio API is unlocked via user interaction in the _enableMobileAudio method. This does not however unlock HTML5 Audio as well. Since HTML5 Audio objects must be individually unlocked, using them without user interaction can be accomplished by pooling a number of activated Audio objects at the same time WebAudio is unlocked, and using those pooled objects whenever a new sound is requested.

Changes:
- Adds a private mobile audio pool to the Howler object.
- Adds a new Howler global configuration named "mobileHtml5AudioPoolDefaultSize" that governs the number of pooled Audio objects, with a starting value of 10.
- Fill the pool in _enableMobileAudio().
- Use Audio objects from the pool when a Sound object is created in HTML5 mode.
- An over-scheduled pool can be configured via the Howler.shouldMobileHtml5AudioPoolErrorWhenEmpty option to still return Audio objects, however they are not guaranteed to be unlocked. This option defaults to 'false'.
@scottanderson42
Copy link
Contributor Author

@gugiserman Thanks for spotting those, too much CoffeeScript in my past. @LukeWalsh I've incorporated the fixes.

@LukeWalsh
Copy link

@scottanderson42 is this working for you when testing locally?

I am trying to use it but still not able to get an HTML5 audio file to work on iOS. In inspecting the Howler object I see that the pool is properly created however the audio is shown as stuck in the "loading" state when I create a Howl object with html5: true.

I also see that onloaderror is firing during the creation of this Howl & giving error code 4. I know it's not an issue with the audio file not being supported by mobile Safari because I'm able to load the same audio file directly in the HTML with:

        <audio controls preload="auto">
          <source src="FILE" />
        </audio>

@LukeWalsh
Copy link

@goldfire have you tried html5 audio on iOS recently?

@scottanderson42
Copy link
Contributor Author

@LukeWalsh I have tested it on iOS11. I have not yet tested on 12.

@LukeWalsh
Copy link

LukeWalsh commented Oct 11, 2018

Hmm ok, I'm running iOS 12 but I would be surprised if that's the difference. And what are you doing in your test? I am using React and creating a Howl object with html5: true in componentDidMount, then I have a button that calls .play() on that Howl object. On the same page I'm loading the same src file using <Audio /> like I mention above.

@LukeWalsh
Copy link

@scottanderson42 did you upgrade to iOS12 and have a chance to test? I'm wondering if there's something I'm missing that's causing my test to fail. If everything is working then this is a useful fix to merge.

@goldfire goldfire added this to the 2.1.0 milestone Nov 14, 2018
@goldfire
Copy link
Owner

Sorry about the delay. I've been out of town and going out of town again today, but I should have time during Thanksgiving week to get caught up on this and some other open PRs and issues and hopefully get this all into a 2.1.0 release.

@goldfire goldfire merged commit d000cff into goldfire:master Dec 8, 2018
@goldfire
Copy link
Owner

goldfire commented Dec 8, 2018

This is now merged into master with some tweaks/simplifications that I've made. I've got some more changes in the autoplay area to get pushed up and then after some further testing I'll try to have 2.1.0 released early next week. Thanks for the work on this!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants