如何使用 AVSystemController 获取 iphone 的当前铃声音量级别
我也试过下面的代码来检查音量级别
MPVolumeView *slide = [MPVolumeView new];
UISlider *volumeViewSlider;
for (UIView *view in [slide subviews]){
if ([[[view class] description] isEqualToString:@"MPVolumeSlider"]) {
volumeViewSlider = (UISlider *) view;
}
}
float val = [volumeViewSlider value];
但是当我打印/检查 val 时,它返回 1.00
我也试过下面的代码
musicPlayer = [MPMusicPlayerController applicationMusicPlayer];
Nslog(@"%f",musicPlayer.volume);
但如果我的手机静音,它也会返回 1.00 事件。我引用下面的链接 How to determine the current level of the iPhone ringer?但我找不到解决办法。
请帮忙。
最佳答案
试试这个:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(volumeChanged:)
name:@"AVSystemController_SystemVolumeDidChangeNotification"
object:nil];
- (void)volumeChanged:(NSNotification *)notification{
NSDictionary*dict=notification.userInfo;
float newVolume =
[[dict objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"]floatValue];
//my comment: newVolume is value that you need
}
关于ios - 在 ios 中使用 AVSystemController 获取铃声音量级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23517085/