0

I would like to present an alert if the sound is 0.

I found this library https://github.com/moshegottlieb/SoundSwitch, but it doesn't seem to work. At least not on a simulator

Luda
  • 7,282
  • 12
  • 79
  • 139

1 Answers1

0

Have you seen this question? They give various answers:

float vol = [[AVAudioSession sharedInstance] outputVolume];
NSLog(@"output volume: %1.2f dB", 20.f*log10f(vol+FLT_MIN));

Nonetheless it doesn't seems to work using the simulator (I'm trying and it always return the same value). This lead me to think maybe it's not something we can check from the simulator. Can you try on a real device? Let me know if it works.

EDIT: Ok so reading about it it seems there's no API avaiable to check silent mode. Anyway what people have found a workaround: Playing a short audio with no volume. If the time when it finishes (minus time when it started) is lower than the actual length of the audio is on mute mode (being in the silent mode the audio will last 0 seconds).

So, here somebody posted a class that do that for you. Let me know if it works

Jaime Alcántara Arnela
  • 2,062
  • 5
  • 25
  • 56
  • It works on Simulator, but it handles only volume buttons. If the volume is up, but the mute button on the side is set to mute, the volume in your function won't be 0 – Luda Sep 25 '18 at 06:42