Detect if speaker is on

Is there a way to detect if users have turned the speaker on or off?

I have an app that really only makes sense if the sound is on. I’d like to be able to tell users (if any) that they need to turn the speaker on if it’s off.

I am sure it is possible, Duolingo app does that.

Let me check.

Yes it seems to be possible using AVAudioSession outputVolume

iOSKit has the feature


Thanks for the tip. I’ve been playing around with things. I’ve got it compiling and running, but it always returns a value of 0.000 on both the simulator and a phone.

If nothing else is offered, you could have a ‘test sound’ button which plays a sound and asks if the output can be heard.
If no, offer suggestions.

From experience, I can tell you my wife often has ‘speaker on’, but the sound is only detectable if you put your head in her handbag where the headphones are.

Actually in iOSKit, the implementation is wrong.

It should be a Single, not a Double:

declare function outputVolume_ lib AVFoundationLib selector "outputVolume" (obj_id as ptr) as Single
Return (outputVolume_(self))

Unfortunately using that method, you can only get the volume once. Subsequent calls will always return the same value.

From the docs:

You can observe changes to the value of this property by using Key-value observing.


That did it! Should be single.

Much thanks.

1 Like