-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Handle audio context state of interrupted #928
Conversation
Can this please get merged, this is causing games for FB Instant Games, to lose sound, if an ad is played, or a phone call is recieved. |
Note, even after this I continued to encounter issues with audio after the screen was off then back on. After investigating, it seemed related to the autoResume after an autoSuspend, which autoResume could attempt to restart the AudioContext based on the timer and not a user touch event, which mobile browsers will ignore. Therefore I'm currently disabling, autoSuspend with Howler appears to track the AudioContext state internally, separately from the actual state. At times this seemed to get out of sync. Therefore I am now calling |
@nanek Would you mind submitting that as a separate issue? I'm going to merge this shortly and wouldn't want to lose track of that. |
Oh sorry, I see what you are saying now. I'll have to look at this a bit more before merging. |
Have the same issue currently. Tested this out on iPhone X (11.3), 6s and 7. Unfortunately, this doesn't fix the issue. Also, no interrupted state was received. Chrome and Safari |
Any progress in the merging here? |
I believe i have the same issue here |
@@ -406,7 +406,7 @@ | |||
if (self.state === 'running' && self._suspendTimer) { | |||
clearTimeout(self._suspendTimer); | |||
self._suspendTimer = null; | |||
} else if (self.state === 'suspended') { | |||
} else if (self.state === 'suspended' || self.state === 'interrupted') { |
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.
Seems that this check will never be true since self.state
doesn't really depend on the AudioContext state (apart from initialisation inside HowlerGlobal.prototype._setup
) and seems unlikely to ever have the interrupted
value.
One way to fix this would be to check the state of AudioContext directly, but the downside is that the code gets more ugly and complicated:
if (self.state === 'running' && self.ctx.state !== 'interrupted' && self._suspendTimer) {
clearTimeout(self._suspendTimer);
self._suspendTimer = null;
} else if (self.state === 'suspended' || self.state === 'running' && self.ctx.state === 'interrupted') {
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.
@nanek I reread the discussion and it turns out that's what you already proposed :)
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.
one more thing: in this case inside the play
method the condition
if (Howler.state === 'running') {
needs to be rewritten as
if (Howler.state === 'running' && Howler.ctx.state !== 'interrupted') {
otherwise sounds will try to play before the context state is resumed
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.
added this fix to this PR #1106
My issue is similar: |
Fix: Sounds stop playing after context is interrupted (fixes #928)
fix audio wich use player-web sometimes not work in wkwebview 场景:打包web-mobile,在ios的wkwebview中加载。 问题1:预加载音频时,this._context.state为running,但是播放的时候this._context.state为interrupted。 问题2:切到后台再切回,this._context.state为interrupted。 解决方案:如果在播放的时候,如果状态为interrupted,强制resume一下。 相关信息:goldfire/howler.js#928
fix audio wich use player-web sometimes not work in wkwebview 场景:打包web-mobile,在ios的wkwebview中加载。 问题1:预加载音频时,this._context.state为running,但是播放的时候this._context.state为interrupted。 问题2:切到后台再切回,this._context.state为interrupted。 解决方案:如果在播放的时候,如果状态为interrupted,强制resume一下。 相关信息:goldfire/howler.js#928
Using Chrome on iOS 11, if the screen is turned off the web audio context goes into an interrupted state. Using Howler, it never resumes and no audio plays after turning the screen back on. This updates the autoResume to also handle the interrupted state.