Skip to content

Commit da398e5

Browse files
authored
Fix web audio capture on Safari (#1006)
- Call `AudioContext.resume()` after creation to ensure it's running - Browsers (especially Safari) may create AudioContext in suspended state, causing the AudioWorklet to silently never fire
1 parent 55bfa20 commit da398e5

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
patch type="fixed" "Fix web audio capture not starting on Safari due to suspended AudioContext"

lib/src/preconnect/audio_frame_capture_web.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,16 @@ class AudioFrameCaptureWeb implements AudioFrameCapture {
8686
final jsTrack = (track as MediaStreamTrackWeb).jsTrack;
8787
final mediaStream = web.MediaStream([jsTrack].toJS);
8888

89-
// 2. Create AudioContext.
89+
// 2. Create AudioContext and best-effort resume it because some browsers require a user gesture and may reject or stall resume()
9090
_audioContext = web.AudioContext();
9191
final ctx = _audioContext!;
92+
try {
93+
await ctx.resume().toDart.timeout(const Duration(seconds: 3));
94+
} on TimeoutException {
95+
logger.warning('[AudioFrameCapture] AudioContext resume timed out, continuing setup');
96+
} catch (e) {
97+
logger.warning('[AudioFrameCapture] AudioContext resume failed: $e, continuing setup');
98+
}
9299

93100
// 3. Register worklet processor via Blob URL.
94101
final blob = web.Blob(

0 commit comments

Comments
 (0)