-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fix AudioContext not being properly resumed on iOS 15. #4062
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really cool to see this fixed! 👏
d74c8ac
to
2c1dacd
Compare
Breaking changes were added which require another review.
Please test this on IE11 as well .. as that could behave differently too (if not already) |
4541e7d
to
094f154
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work. Anybody else wants to have a look?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l approve of this!
this._resumeContext = () => { | ||
if (!this.context || this.context.state === 'running') { | ||
USER_INPUT_EVENTS.forEach((eventName) => { | ||
window.removeEventListener(eventName, this._resumeContext); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inception. i like.
Fixes #3977
Fix issues on the
AudioContext
not being properly resumed, especially on iOS 15. This is done by explicitly calling.resume()
on theAudioContext
when required. Extra checks were added to make sureresume
is only called when the window is being re-focused, and the state is going fromsuspended
orinterrupted
back torunning
- otherwise exceptions are thrown. Additionally, if for any reason the context can't be resumed successfully, the Auto-Play event listeners are re-bound so that the audio can be resumed later.Documentation:
As far as I could test, this new code behaves well with all of our current target devices and browsers, but we could also consider using external libraries for this kind of stuff, such as the ones below (pending analysis, of course).
New test scenarios in Safari iOS 15:
I confirm I have read the contributing guidelines and signed the Contributor License Agreement.