ios - 在 ios 中使用 AVSystemController 获取铃声音量级别

标签 ios volume avsystemcontroller

如何使用 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/

相关文章:

objective-c - 允许根据 url 字符串选择表格 View 单元格

ios - AVSystemController_SystemVolumeDidChangeNotification 第一次没有回调

ios - 在 iPhone App 中使用 AVSystemController

windows - 在Windows命令行中获取卷名的驱动器号

iphone - 以编程方式使 iOS 设备静音/静音?

objective-c - 一次只允许某个 UIGestureRecognizer 执行

ios - ios中的ssh协商过程

ios - 在函数中使用闭包

c# - 如何在 C# 和 Windows 7 中设置音量?

javascript - Javascript-我可以一次更改所有音频元素的音量吗?