本文介绍了在 ios 中使用 AVSystemController 获取铃声音量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 AVSystemController 获取 iphone 当前的铃声音量

How can i get iphone's current ringer volume level using AVSystemController

我也试过下面的代码来检查音量

I also tried below code to check volume level

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

But when i print / check val, it returns 1.00

我也试过下面的代码

musicPlayer = [MPMusicPlayerController applicationMusicPlayer];
Nslog(@"%f",musicPlayer.volume);

但如果我的手机静音,它也会返回 1.00 事件.我参考下面的链接如何确定当前 iPhone 铃声的电平? 但我找不到解决方案.

But it also returns 1.00 event if my phone is silent. I refer below linkHow to determine the current level of the iPhone ringer? but i could not find solution.

请帮忙.

推荐答案

试试这个:

[[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 中使用 AVSystemController 获取铃声音量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-19 20:16