Commit 528ff62
Recover AudioStream when system audio output device changes (#274)
* Restart AudioSource when system audio output device changes
Unity stops every AudioSource during the audio engine reset that follows a
system output device change (per AudioSettings.OnAudioConfigurationChanged
docs). Without re-playing the source, OnAudioFilterRead stops firing and
the AudioStream goes silent until recreated. Subscribe to the event,
re-Play() the source, and clear the ring buffer so we don't drain stale
frames accumulated during the device-change blackout.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Re-attach AudioProbe on audio config change, not just re-Play
Calling _audioSource.Play() alone isn't enough to recover after Unity
tears down the audio engine: the OnAudioFilterRead node from the
existing AudioProbe stays detached from the rebuilt audio graph and
no callbacks fire. Destroy the old probe, AddComponent a fresh one,
and Stop()/Play() the source so Unity re-registers the filter node.
Also drop the deviceWasChanged gate (programmatic Reset() needs the
same recovery) and switch to a visible Debug.Log so the event firing
can be confirmed in the Console.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 2d7509e commit 528ff62
2 files changed
Lines changed: 36 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
76 | 81 | | |
77 | 82 | | |
78 | 83 | | |
| |||
211 | 216 | | |
212 | 217 | | |
213 | 218 | | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
214 | 247 | | |
215 | 248 | | |
216 | 249 | | |
| |||
285 | 318 | | |
286 | 319 | | |
287 | 320 | | |
| 321 | + | |
288 | 322 | | |
289 | 323 | | |
290 | 324 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| 125 | + | |
125 | 126 | | |
126 | 127 | | |
127 | 128 | | |
| |||
0 commit comments