AVAudioSession's OutputVolume never changes

烈酒焚心 提交于 2019-11-29 13:53:42

Use KVO, and make sure to activate the sharedInstance:

[[AVAudioSession sharedInstance] setActive:YES error:nil];
[[AVAudioSession sharedInstance] addObserver:self forKeyPath:@"outputVolume" options:NSKeyValueObservingOptionNew context:nil];

I checked in iOS 12:

[[AVAudioSession sharedInstance] setActive:YES error:nil];
float vol = [[AVAudioSession sharedInstance] outputVolume];
NSLog(@"outputVolume: %f", vol);

I am finding I need to actually output sound in order for [AVAudioSession sharedInstance].outputVolume to be accurate.

In other words - [AVAudioSession sharedInstance].outputVolume is a little flakey - you need to play audio for it to return the correct volume.

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