Ignore:
Timestamp:
08/07/13 13:49:25 (7 years ago)
Author:
Jonathon Horsman <jonathon@…>
Branches:
master, Servo, Tab_Interface, pyramid
Children:
7945ecb
Parents:
6fc29d0
Message:

Add check for headphones being plugged in

File:
1 edited

Legend:

Unmodified
Added
Removed
  • iOS/Orbit/Orbit/SignalConverter.m

    rde10cbc r359a504  
    4646        yaw = 78; 
    4747        pitch = 31; 
     48         
     49        // initialise the audio session - this should only be done once 
     50        AudioSessionInitialize(NULL, NULL, NULL, NULL); 
    4851    } 
    4952    return self; 
     
    140143{ 
    141144    AudioSessionSetActive(YES); 
    142     return 1.0 == [[AVAudioSession sharedInstance] outputVolume]; 
     145    float volume = [[AVAudioSession sharedInstance] outputVolume]; 
     146    NSLog(@"Volume is %f", volume); 
     147    return 1.0 == volume; 
     148} 
     149 
     150- (BOOL) isAudioJackPlugged 
     151{ 
     152    UInt32 routeSize; 
     153     
     154    // oddly, without calling this method caused an error. 
     155    AudioSessionGetPropertySize(kAudioSessionProperty_AudioRouteDescription, &routeSize); 
     156    CFDictionaryRef desc; // this is the dictionary to contain descriptions 
     157     
     158    // make the call to get the audio description and populate the desc dictionary 
     159    AudioSessionGetProperty (kAudioSessionProperty_AudioRouteDescription, &routeSize, &desc); 
     160 
     161    // the dictionary contains 2 keys, for input and output. Get output array 
     162    CFArrayRef outputs = CFDictionaryGetValue(desc, kAudioSession_AudioRouteKey_Outputs); 
     163     
     164    // the output array contains 1 element - a dictionary 
     165    CFDictionaryRef dict = CFArrayGetValueAtIndex(outputs, 0); 
     166     
     167    // get the output description from the dictionary 
     168    CFStringRef output = CFDictionaryGetValue(dict, kAudioSession_AudioRouteKey_Type); 
     169     
     170    /** 
     171     These are the possible output types: 
     172     kAudioSessionOutputRoute_LineOut 
     173     kAudioSessionOutputRoute_Headphones 
     174     kAudioSessionOutputRoute_BluetoothHFP 
     175     kAudioSessionOutputRoute_BluetoothA2DP 
     176     kAudioSessionOutputRoute_BuiltInReceiver 
     177     kAudioSessionOutputRoute_BuiltInSpeaker 
     178     kAudioSessionOutputRoute_USBAudio 
     179     kAudioSessionOutputRoute_HDMI 
     180     kAudioSessionOutputRoute_AirPlay 
     181     */ 
     182 
     183    NSLog(@"Output: %@ is %@", output, kAudioSessionOutputRoute_Headphones); 
     184    return CFStringCompare(output, kAudioSessionOutputRoute_Headphones, 0) == kCFCompareEqualTo; 
    143185} 
    144186 
Note: See TracChangeset for help on using the changeset viewer.