Reputation: 1888
I want to play buffered audio in my game for long music files (sort of streaming). It seems I have to use html audio: Buffered audio in SoundJS
However, I still want to use webaudio for sound effects (to avoid delay on mobile browsers, for example).
Is this doable? Can I use html audio for some sounds and web audio for other sounds in the same page, or I'll have to manually create some html audio tags for my music files?
Upvotes: 2
Views: 371
Reputation: 440
You actually can stream into the web audio api, it adds a fair amount of complexity though. You will have to manually append audio data fragments to the buffer you are playing as they come in and move loading and decoding into a web worker so you don't block the main thread. Because web audio isn't available in web workers you have to use a third party decoding library. I switched to Aurora in a web worker for loading and decoding audio in an app, it downloads and decodes the audio in chunks and doesn't block main thread. Also decode audio data from the web api uses up all your cpu in Firefox, up to 95% on my machine which is fairly fast. Ontop of that it allowed me to load far more audio assets without crashing the browser tab, 100+ 20mb wav files where ad on the main thread the browser tab would crash at a little over 40.
Upvotes: 4