iOS开发之音乐播放----监听系统音量变化

需要在:didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法中加入一下监听事件:

    //监听系统音量控制
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(volumeChanged:)
                                                 name:@"AVSystemController_SystemVolumeDidChangeNotification"
                                               object:nil];

 然后实现对应的通知事件: 
  

- (void)volumeChanged:(NSNotification *)notification
{
    float volume =
    [[[notification userInfo]
      objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"]
     floatValue];
    
    NSLog(@"%f", volume);
}





你可能感兴趣的:(IOS原创)