Close AudioContext when timeline is complete


(Corrine) #1

Hey guys,

I’m currently having a issue where I receive this error:

Uncaught DOMException: Failed to construct ‘AudioContext’: The number of hardware contexts provided (6) is greater than or equal to the maximum bound (6).

The problem comes from the HYPE.js file.
So is there a way to close the AudioContext when the animation timeline is complete?

Thanks,

Corrine


#2

Hi @Corrine

AudioContext is quite complex in its use. Could you supply some code so that we can see how you are using it?

Ideally you would store any sounds in buffers


(Jonathan Deutsch) #3

That’s an interesting error; as @DBear said, could you send a zip of your .hype document so we can take a look? (If confidential, please send to support@tumult.com and we can keep it private). It would also be useful to know what browser, version, device, and OSes you are using. Thanks!


#4

@Corrine it’s like fumbling around in the dark for something when we can’t see how it’s used in context.

There are methods such as AudioContext.close() and AudioContext.suspend() but we have to take into account browser issues, etc. Bearing in mind this doesn’t release the AudioContext completely but does allow additional contexts to be created. The error you have stated is quite self-explanatory i.e you can only have a maximum of 6 AudioContexts in any one document. That being said and as I mentioned, you only ever really need one context and you would store sounds in buffers. This way it helps with syncing.


(Corrine) #5

Thanks for your replies guys,

Here’s the hype document:

inter_page11_shelf.zip (2.8 MB)

This error only happens on Google Chrome it would seem.
I’m on a PC using Windows 10.

The animation is used in an online course page like so:

Clicking on the page numbers at the bottom does not refresh the page (it loads data from a database into the same page again). So basically if i were to click page 11 (the page the animation is on) 6 times, I get the error.

@DBear can you elaborate on “store sounds in buffers”?

Thanks.


#6

HI @Corrine

first of all, great animation!

secondly, I must apologise as I assumed that you were using code, with AudioContext.

I may suggest a workaround for the moment, and that is to prevent a second press of the button for the page. You could do this by placing an element over it with an action for the press and then hiding or moving that element immediately after (probably with your animation).

The reason being (and @jonathan would have more insight into this) is that Hype (sometimes) uses the Web Audio API to load its sounds and because you’re not reloading the page it’s creating new contexts for the audio files (until it reaches 6). This is a hunch and may be wrong. I’m speculating here and this isn’t a definitive answer. :slight_smile: I’m sure Jonathan could give more information.


(Jonathan Deutsch) #7

This is indeed a Hype bug (rather it did not take Chrome’s limit into account). Thanks for reporting this. I just made a specific fix to better reuse contexts and overall improved the safety to fallback to the HTML5 <audio> tag if there’s ever a problem, which will be in the next version of Hype. You’ll need to re-export with that.

Unfortunately I can’t think of any workarounds to the problem short of not reloading the document more than 6 times :slight_smile:. If you’re interested in getting the fix sooner, you’re welcome to join the beta program; let me know if that interests you.

(and that is a fun document btw!)


(Corrine) #8

Thanks again for your responses and advice :slight_smile:

@jonathan it’d be great if I could join the beta program!


#9

Wouldn’t my solution of stopping the user from reloading the document (not pressing the page 11 button) work? :slight_smile:


(Jonathan Deutsch) #10

I’ve added you, thanks!

As in cure the disease, kill the patient? :smile:


#11

:slight_smile:


(Corrine) #12

@DBear sort of! however I get the error again when I sequentially go through the pages anyway as there are other animations with sounds being loaded beforehand :frowning:

@jonathan thanks very much :slight_smile: