sound icon indicating copy to clipboard operation
sound copied to clipboard

Chrome 66 - The AudioContext was not allowed to start

Open otoinsa opened this issue 7 years ago • 10 comments

Hi! First of all - thanks for this great sound library! :)

Since last Chrome update there's a new policy: https://developers.google.com/web/updates/2017/09/autoplay-policy-changes#webaudio

Needless to say, I don't like this new policy.

image

My game audio context gets paused :( Since the game has no mouse intereaction, it never gets resumed.

However if I do press on the canvas with a pointer device, it resumes the audio context. PIXI.sound.resumeAll() does not help either.

Is there no way to work around this?

I really like this library and I've been using it for my game; It's still in active development and pixi-sound is an important part of it.

otoinsa avatar May 04 '18 09:05 otoinsa

Thanks for the compliments.

I don’t think you can avoid this. We are heading to a world where all audio and video media requires an interaction. I’m not a huge fan either. You can design around it by creating a start button?

bigtimebuddy avatar May 04 '18 10:05 bigtimebuddy

It's a good idea, but one of the target devices (arcade box) will only have button controls connected to it (directional joystick, 5 action buttons), currently a keypress is not resuming the audio context. :(

I guess I can build with an older version of Chromium for now until the Chrome devs implement some none pointer-device way or resuming audio context...

otoinsa avatar May 05 '18 22:05 otoinsa

I wonder if there is there a flag in Chrome to prevent this behavior?

bigtimebuddy avatar May 05 '18 23:05 bigtimebuddy

chrome://flags/ does have an "Autoplay policy" flag actually, so far it works. :)

otoinsa avatar May 09 '18 11:05 otoinsa

Follow-up article: https://www.bleepingcomputer.com/news/google/google-fixes-issue-that-broke-millions-of-web-based-games-in-chrome/

Looks like they temporarily reverting the change until more developers can integrated interaction-to-play audio. I might add a note about this in the readme because it's an important design consideration.

bigtimebuddy avatar May 16 '18 15:05 bigtimebuddy

Sorry to bump an old post--

I added a "start" button that then plays the main menu state and starts the audio. Yet, I still get this warning:

The Web Audio autoplay policy will be re-enabled in Chrome 70 (October 2018). Please check that your website is compatible with it. https://goo.gl/7K7WLu

Is that warning something that always pops up? OR is it telling me my current implementation simply doesn't work correctly? Thanks!

OptimusPi avatar Sep 06 '18 18:09 OptimusPi

How do we resume the audio context after user interaction?

OptimusPi avatar Sep 14 '18 01:09 OptimusPi

Based on this setter @OptimusPi I believe you should be able to set paused = false, ala

PIXI.sound.context.paused = false;

chipbell4 avatar Sep 05 '19 20:09 chipbell4

maybe it could be useful for someone, it took me a while sorting out those annoying warnings.

You can load dynamically 'pixi-sound' after a user click/swipe and store it in a lazy loader var.

if (!this.pixiSound) {
  this.pixiSound = await import('pixi-sound')
}

then, in order to use it:

  this.pixiSound.default

useless-stuff avatar Sep 25 '19 23:09 useless-stuff

Building off the previous comment, this work well for me:

document.addEventListener('click', async () => {
  globalThis.PIXI.sound = (await import('pixi-sound')).default;
}, { once: true });

connorjclark avatar May 09 '21 08:05 connorjclark