0

I'm using the method described here Get name of AirPlay device using AVPlayer to retrieve the name of the AirPlay device connected.

But AudioSessionGetProperty and kAudioSession_AudioRouteKey_Outputs are deprecated in iOS7. I'm looking for an alternative method to do this :)

Community
  • 1
  • 1
flopr
  • 450
  • 4
  • 23

1 Answers1

2

Starting from iOS6 AudioSession exposes currentRoute to you, which allows retrieving it's port information as well as listening to audioRouteChangeNotification. (so you no longer need to use C-based API from AudioToolbox framework):

NSString* airplayName = [self activeAirplayOutputRouteName];
if (airplayName) {
    //airplay is active

}

(what you want to get is the portDescription of currentAudioRoute):

- (NSString*)activeAirplayOutputRouteName
{
    AVAudioSession* audioSession = [AVAudioSession sharedInstance];
    AVAudioSessionRouteDescription* currentRoute = audioSession.currentRoute;
    for (AVAudioSessionPortDescription* outputPort in currentRoute.outputs){
        if ([outputPort.portType isEqualToString:AVAudioSessionPortAirPlay])
            return outputPort.portName;
    }

    return nil;
}
ambientlight
  • 7,212
  • 3
  • 49
  • 61