Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Audio Output Routes for AirPlay

I have looked but can't find a way to access the Audio Output Routes so i can detect if the audio is coming out via AirPlay.

This is what i found in the Documentation for iOS 5.0

kAudioSessionOutputRoute_AirPlay

Discussion

These strings are used as values for the kAudioSession_AudioRouteKey_Type key for the dictionary associated with the kAudioSession_AudioRouteKey_Outputs array.

I can't find a way to get access to the kAudioSession_AudioRouteKey_Outputs array.

Thanks

like image 689
Bassem Avatar asked Dec 04 '11 22:12

Bassem


People also ask

How do I AirPlay audio?

Easy Pairing. Connect the adapter to power and your cables to the audio input of your equipment, and you're ready to go. Just tap the AirPlay button on your music app to instantly start playing on your speakers.

How do I connect my speakers to AirPlay?

Go into the Wi-Fi under Settings on your iPhone/iPad. Select the speaker you want to set up AirPlay under “SET UP NEW AIRPLAY SPEAKER...” on the lower part of the display. Choose the Wi-Fi network you want to connect this speaker to, then press Next.

Can you AirPlay video to a TV and audio to a speaker?

AirPlay 2 has a number of different uses. You can use it to mirror an iPhone or Mac on another screen (great for sharing video and pictures); you can stream video from a compatible app to a TV (Netflix, Hulu etc); and you can stream audio to speakers.


1 Answers

Even if Bassem seems to have found a solution, for completion's sake, here's how to detect whether the current output route is AirPlay or not:

- (BOOL)isAirPlayActive{
    CFDictionaryRef currentRouteDescriptionDictionary = nil;
    UInt32 dataSize = sizeof(currentRouteDescriptionDictionary);
    AudioSessionGetProperty(kAudioSessionProperty_AudioRouteDescription, &dataSize, &currentRouteDescriptionDictionary);
    if (currentRouteDescriptionDictionary) {
        CFArrayRef outputs = CFDictionaryGetValue(currentRouteDescriptionDictionary, kAudioSession_AudioRouteKey_Outputs);
        if (outputs) {
            if(CFArrayGetCount(outputs) > 0) {
                CFDictionaryRef currentOutput = CFArrayGetValueAtIndex(outputs, 0);
                CFStringRef outputType = CFDictionaryGetValue(currentOutput, kAudioSession_AudioRouteKey_Type);
                return (CFStringCompare(outputType, kAudioSessionOutputRoute_AirPlay, 0) == kCFCompareEqualTo);
            }
        }
    }

    return NO;
}

Keep in mind that you have to #import <AudioToolbox/AudioToolbox.h> and link against the AudioToolbox framework.

like image 178
avf Avatar answered Oct 16 '22 03:10

avf