ios get airplay name

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 }

 

posted on 2015-07-15 11:43  XCoderLiu  阅读(320)  评论(0编辑  收藏  举报

导航