Mute/Silence an iOS device programmatically?

六眼飞鱼酱① 提交于 2019-11-27 09:20:46
MSU_Bulldog

This worked for me, I have a button that toggles sound on and off in a game. I set the float to 10 when I want sound on and 0 when I want sound off.

float value = 0.0f;
AudioSessionSetProperty(kAudioSessionProperty_CurrentHardwareOutputVolume, sizeof(float), &value);

Update:

Another option that is still working with iOS 9.1

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

For Swift:

let volume = AVAudioSession.sharedInstance().outputVolume   
print("Output volume: \(volume)")

Sources for updates answer: Get System Volume iOS

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!