Bug 276016 - REGRESSION (iOS 17.4.1 - 17.5.1): Web Audio sounds stop playing after losing focus of safari in iOS 17.5.1
Summary: REGRESSION (iOS 17.4.1 - 17.5.1): Web Audio sounds stop playing after losing ...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Audio (show other bugs)
Version: Other
Hardware: iPhone / iPad iOS 17
: P2 Major
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2024-06-28 14:50 PDT by condeagustin
Modified: 2024-08-18 21:58 PDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description condeagustin 2024-06-28 14:50:32 PDT
After upgrading to iOS 17.5.1 (in any iOS device), when losing and then gaining focus of safari, any web audio sound that was playing (before losing focus) is off for the rest of the session. Even if you tap on a UI element that is supposed to produce a sound, the sound never comes back. This issue is 100% reproducible only on iOS 17.5.1. In the previous iOS version (e.g. 17.4.1) I tested it and this issue never happened

You can use the following web audio sample to repro the issue from safari iOS 17.5.1 (taken from the official web audio context documentation https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/resume):

1. Open https://mdn.github.io/webaudio-examples/audiocontext-states/ from iOS 17.5.1 safari
2. Tap on the "create context" button. You hear a constant sound
3. Lose focus of safari (e.g. minimize it) and the sound stops playing
4. Gain focus of safari and you will see that the sound is never heard again. In a previous iOS version (or in any other non-iOS browser), such sound keeps playing just fine after losing focus. For some reason, iOS 17.5.1 breaks the web audio context when you lose focus, and the only way to hear sounds again is to create a new instance of web audio context every time you gain focus
Comment 1 Radar WebKit Bug Importer 2024-06-28 17:34:56 PDT
<rdar://problem/130787868>
Comment 2 Matthew Windwer 2024-07-26 13:23:09 PDT
I was able to reproduce this using the above steps for iOS 17.6 RC. The audioCtx.state (check console) is "interrupted" at the end of step 3. The solution is to suspend and resume the audio context when Safari is resumed, which can be done on visibilitychange. I'm not sure whether or not this should be necessary.

There is another bug that causes a similar issue, but the context remains in the "running" state and cannot be heard, and sometimes cannot be resumed. See https://bugs.webkit.org/show_bug.cgi?id=276687#c6 for repro steps.
Comment 3 hamish@risingsoftware.com 2024-08-18 21:58:52 PDT
On 17.6.1, the audiocontext seems to return from interrupted to running when Safari becomes visible again.

But once when I had the example page open in a background tab, and another tab using web audio in the foreground, I heard the example page fade out and its currentTime stop advancing, though the state was still running.