Repository navigation
PlatformAudio: the music comes back after the app returns, and follows only the game's music switch - #224
Merged
Conversation
fleon
marked this pull request as ready for review
November 28, 2026 11:17
fleon
enabled auto-merge
November 28, 2026 11:19
|
Claude review (house rules) |
|
Claude review (house rules), correction: CONTRIBUTING.md is in the repo. I read it after posting the comment above, and it doesn't change the review. Still 1 inline comment. |
fleon
disabled auto-merge
November 28, 2026 11:19
…s only the game's music switch The soundtrack no longer steps aside for other apps' audio (`stepsAsideForOtherAudio`, iOS's secondary-audio hint, Android's isMusicActive check), which misjudged what was playing and, once it stepped aside, often never came back. iOS: an ambient session (mixes with other apps, never interrupted by their playback, silenced by the Ring/Silent switch). The soundtrack picks up on didBecomeActive with the session reactivated, rather than on willEnterForeground while the app is still in the background, so it also comes back after an interruption that never says it ended (Siri, a declined call). Interruptions told late for a suspended app are ignored. Android: the game takes audio focus each time it comes back from a stop while its music is on (Android keeps an app that lost focus muted until it asks again), and holds none while music is off. Focus asked during a call is granted as it ends. AndroidPlatformServices.Audio replaces audioFocusChanged; AudioManager.audioFocusDidChange(interrupted:) replaces audioFocusDidChange(otherAudio:interrupted:).
… under the game's own key Services install before the game configures its audio, so the switch the shell first heard was read under the default key: configure posts musicEnabledDidChange too (the policy ignores a repeat).
fleon
force-pushed
the
fix/music-resumes-on-foreground
branch
from
November 28, 2026 11:21
027d41a to
0bb39dd
Compare
…sic switch silences the soundtrack The game holds no audio focus, so its soundtrack mixes with the player's own music, which plays on, and nothing (another app's playback, Android 12's fade-out, a call) silences it. Calls don't pause it either: only the game's music switch does. Gone with focus: AudioFocusPolicy, the device.audioFocus call and the audio event, AndroidPlatformServices.Configuration.audioFocusChanged, .toolkit's audio parameter, AudioManager.audioFocusDidChange and musicEnabledDidChange.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Players reported that the background music stops when they leave the game and doesn't come back. This makes it come back on return to the foreground, after a plain app switch and after an interruption, whenever the game's music switch is on. It also removes the feature that silenced the soundtrack while another app played audio (
stepsAsideForOtherAudio), which misjudged whether other audio was playing.Only the game's music switch silences its music now, on both platforms. The soundtrack mixes with other apps' audio. The player's own music plays on under it and is never paused by the game, and the game never steps aside or pauses for other audio or calls.
Root cause
secondaryAudioShouldBeSilencedHintwas true, and the hint was read only at launch and through its notification, which iOS sends only to apps in the foreground. After the player used another app with audio, the game came back still thinking audio was playing, and stayed silent. The hint is also true while another app merely holds a non-mixable session. On Android the game readisMusicActive()as it returned and took no focus if anything was playing. It never asked again, and on Android 12+ an app that lost focus stays muted until it asks again.willEnterForeground, while the app is still in the background state. Nothing restarted it ondidBecomeActive, the one moment that comes after an interruption that never says it ended (Siri, a declined call).What changed
iOS / tvOS / Mac Catalyst (
AppleAudioBackend).ambient(the explicit.mixWithOtherswas redundant and is gone). I picked it because it's the one category where other apps can't silence the game's music. It mixes with other apps' audio: starting Music or a video doesn't interrupt the game's music, and the game never stops the player's. It honours the Ring/Silent switch, as games are expected to..soloAmbientwould stop the player's music on every launch, and other apps' playback would interrupt the game..playbackwould ignore the silent switch.didBecomeActive, with the session reactivated first (off the main thread). An interruption's end also reactivates the session before the restart..appWasSuspended/WasSuspendedKey): pausing for one would wait for an end that never comes.onOtherAudioChange,isOtherAudioPlayingand the silence-hint observer.Android (
DeviceServices)AudioFocusPolicy, the focus requests and theaudioevent are gone.API (breaking; each game fixes it when it next moves its submodule)
AudioConfiguration.stepsAsideForOtherAudioAudioManager.audioFocusDidChange(otherAudio:interrupted:)AndroidPlatformServices.Configuration.audioFocusChanged.toolkit'saudio:parameter.toolkit(gameCenter:…)with the defaultAudioConfigurationneeds no changes, as is the case for Sheeping Around's main. A game that passesstepsAsideForOtherAudio:, wiresaudioFocusChangedby hand or passesaudio:to.toolkitdrops that line.AGENTS.md (the rule that kept the steps-aside default), README and the template README now describe the new behaviour.
Verification
swift test --package-path Platformpasses. Platform's tests pass on Mac Catalyst.Scripts/check-android.sh arm64-v8apasses. The Android library's unit tests andassembleDebugpass.swift testand the iOS and tvOS Platform builds. The later commits change onlyAudioManager, which those builds compile as before, and remove the Android focus code. CI covers them again.