ios 開發中 捕獲耳機插拔事件


void audioRouteChangeListenerCallback (
void *inUserData,
AudioSessionPropertyID inID,
UInt32 inDataSize,
const void *inData)
{
UInt32 propertySize = sizeof(CFStringRef);
AudioSessionInitialize(NULL, NULL, NULL, NULL);
CFStringRef state = nil;
AudioSessionGetProperty(kAudioSessionProperty_AudioRoute
,&propertySize,&state); it

NSLog(@"%@",(NSString *)state);//return @"Headphone" or @"Speaker" and so on.
}
- (void)viewDidLoad {
[super viewDidLoad]; io

AudioSessionInitialize (NULL, NULL, NULL, NULL);
OSStatus status = AudioSessionAddPropertyListener(
kAudioSessionProperty_AudioRouteChange,
audioRouteChangeListenerCallback,self);
//if(status == 0){//ok;}
} List

相關文章
相關標籤/搜索