标签:
tarting from iOS7 AudioToolbox API for currentRoute becomes deprecated:
Apple instead made currentRoute API available to you in AudioSession, which allows retrieving it‘s port information as well as listening to audioRouteChangeNotification in a nice way:
NSString* airplayName = [self activeAirplayOutputRouteName]; if (airplayName) { //airplay is active } [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioRouteHasChangedNotification:) name:AVAudioSessionRouteChangeNotification object:[AVAudioSession sharedInstance]];
1 - (NSString*)activeAirplayOutputRouteName 2 { 3 AVAudioSession* audioSession = [AVAudioSession sharedInstance]; 4 AVAudioSessionRouteDescription* currentRoute = audioSession.currentRoute; 5 for (AVAudioSessionPortDescription* outputPort in currentRoute.outputs){ 6 if ([outputPort.portType isEqualToString:AVAudioSessionPortAirPlay]) 7 return outputPort.portName; 8 } 9 10 return nil; 11 } 12 13 - (void)audioRouteHasChangedNotification:(NSNotification*)notification 14 { 15 //do something 16 }
标签:
原文地址:http://www.cnblogs.com/XCoderLiu/p/4647887.html