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

Chrome 66 - The AudioContext was not allowed to start #65

Open
otoinsa opened this issue May 4, 2018 · 10 comments
Open

Chrome 66 - The AudioContext was not allowed to start #65

otoinsa opened this issue May 4, 2018 · 10 comments

Comments

@otoinsa
Copy link

otoinsa commented May 4, 2018

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.

@bigtimebuddy
Copy link
Member

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?

@otoinsa
Copy link
Author

otoinsa commented May 5, 2018

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...

@bigtimebuddy
Copy link
Member

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

@otoinsa
Copy link
Author

otoinsa commented May 9, 2018

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

@bigtimebuddy
Copy link
Member

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.

@OptimusPi
Copy link

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
Copy link

How do we resume the audio context after user interaction?

@chipbell4
Copy link

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

PIXI.sound.context.paused = false;

@useless-stuff
Copy link

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

@connorjclark
Copy link
Contributor

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

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

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

No branches or pull requests

6 participants