在想要添加監(jiān)聽設(shè)備音量變化的地方加入下面兩句代碼
//監(jiān)聽音量變化的系統(tǒng)通知
selector:@selector(systemVolumeDidChangeNoti:) name:@"AVSystemController_SystemVolumeDidChangeNotification" object:nil];
//開始接收遙控事件
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
/*必須用通知里面的userInfo鍵值對(duì)中的AVSystemController_AudioVolumeNotificationParameter
只有這里面的值才是最新的音量值落午,如果還是用 [AVAudioSession sharedInstance].outputVolume皮官,得到的還是舊的音量值(它們需要過一會(huì)才會(huì)被設(shè)成新值)*/
-(void)systemVolumeDidChangeNoti:(NSNotification* )noti{
//目前手機(jī)音量
if ([noti.name isEqualToString:@"AVSystemController_SystemVolumeDidChangeNotification"]) {
NSDictionary *dic = noti.userInfo;
self.circleView.progress = [dic[@"AVSystemController_AudioVolumeNotificationParameter"] floatValue];
}
}