开发者

Objective-C: volumeChanged wasn't called even add a Observer for AVSystemController_SystemVolumeDidChangeNotification?

开发者 https://www.devze.com 2023-04-13 03:51 出处:网络
- (void)viewDid开发者_如何学PythonLoad { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(volumeChanged:) name:@\"AVSystemController_SystemVolumeDidChangeNotification\" object
- (void)viewDid开发者_如何学PythonLoad {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(volumeChanged:) name:@"AVSystemController_SystemVolumeDidChangeNotification" object:nil];
}

- (void)volumeChanged:(NSNotification *)notification{

    float volume = [[[notification userInfo] objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"] floatValue];
    //[self innerSetVolume:volume];
}

volumeChanged will not be called when I push the up/down hardware volume button on device. somebody met the question before?

PS:my test device is iPod touch with iOS 4.3, not iPhone.


I believe you need to start up Audio Session Services in order for those notifications to fire.

Here's the documentation for the call -- http://developer.apple.com/library/ios/documentation/AudioToolbox/Reference/AudioSessionServicesReference/Reference/reference.html#//apple_ref/c/func/AudioSessionSetActive

0

精彩评论

暂无评论...
验证码 换一张
取 消