feat: AudioManager.getSystemVolume() — synchronous system volume read - #1211
Open
lpmv wants to merge 1 commit into
Open
feat: AudioManager.getSystemVolume() — synchronous system volume read#1211lpmv wants to merge 1 commit into
lpmv wants to merge 1 commit into
Conversation
AudioManager can observe volume changes (observeVolumeChanges + the volumeChange event) but has no way to read the volume BEFORE any change has fired - e.g. an app that wants to warn 'your volume is at the floor' at the moment the user presses play cannot know the current level until the user happens to press a volume button. This adds the synchronous read on the exact scale the volumeChange event already reports: - iOS: AVAudioSession.outputVolume - Android: STREAM_MUSIC volume / STREAM_MUSIC max volume (0..1) exposed as AudioManager.getSystemVolume(): number via the TurboModule spec, mirroring getDevicePreferredSampleRate's blocking-synchronous form.
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.
Why
AudioManagercan observe volume changes (observeVolumeChanges+ thevolumeChangeevent) but has no way to read the volume before any change has fired. An app that wants to warn "your volume is at the floor" at the moment the user presses play cannot know the current level until the user happens to press a volume button.What
A synchronous read on the exact scale the
volumeChangeevent already reports:AVAudioSession.outputVolumeSTREAM_MUSICvolume as a fraction of its maximumExposed via the TurboModule spec mirroring
getDevicePreferredSampleRate's blocking-synchronous form; the iOS implementation delegates toAudioSessionManagerlike its siblings.Notes
The JSDoc carries the honest iOS caveat: a cold read before any volume-change event can report a stale or zero value on some iOS versions (KVO on
outputVolumeis the trustworthy stream once it speaks); callers who care can treat an exact 0.0 cold read as suspect. That caveat exists with or without this API — this just gives apps the same read the KVO baseline uses.