question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AudioLoader doesn't behave correctly without user interaction

See original GitHub issue

The AudioLoader makes use of window.AudioContext. This is problematic because any use of audio in Chrome requires a user interaction. While that’s normally solvable by triggering audio with a click, this isn’t suitable when dealing with asset loading, as this sort of thing should start the moment the page loads.

For example, I’d like to make use of AudioLoader when the page first loads, to download audio files along with other assets. If I do this, Chrome may bring up this warning (although this seems to be intermittent):

The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu

To be clear, I have a click event for playing the sounds. Currently, we need a click event even when loading the sounds.

Looking at the source code for AudioLoader, this is happening because it’s trying to load and decode the audio in the same step.

There doesn’t seem to be a clear solution on how to fix this. It’s a real pain that Chrome is restricting even the decoding of audio. Perhaps audio files need to be treated as normal files while downloading, and then there is a separate step (after a user interaction to start the app) for the audio to be decoded.

Tested on Chrome, Windows. Three r116.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Mugen87commented, May 1, 2020

Maybe you can convince the Chromium project to alter its audio policy 😉

1reaction
funwithtrianglescommented, May 1, 2020

Sure, I think a splash screen makes sense, but while it’s displaying is usually the best time to load all of your assets. If the user clicks “start” and is then faced with another loading screen, this isn’t ideal.

I’d agree that this is a matter of application design but a library can help with common patterns. Loading a second round of assets after clicking “start” is not a common pattern.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Playing sound with no click interaction within JS doesn't work?
Very old subject based on my research and this research states the user must interact via clicking, e.g., in order for the sound...
Read more >
AudioLoader – three.js docs
If the server does not set the Content-Length header; .total will be 0. onError (optional) — Will be called when load errors. Begin...
Read more >
Essentia streaming mode architecture
In the streaming mode, you do not call the compute() method yourself anymore. ... but the user side gets simplified a lot: the...
Read more >
Release 0.6.0 - OpenSoundscape
development branch, use the GitHub web interface to create a merge or ... This function returns a DataFrame of clips, but does not...
Read more >
An Exploratory Study of Bugs in Extended Reality Applications ...
bugs require special user interactions to manifest, the large ... scenes correctly on Safari but not on Chrome for iOS devices.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found