1

Possible Duplicate:
How can I find out if an external headset is connected to an iPhone?

I'm developing an audio-player application and in one of modes(playing mode) i want to detect the status of headset, if the jack is plugged in it should plays else shouldn't.

EDIT Below is a snippet from my code, there are explanations too about what I'm trying to do. I found most of code from other threads on SO, but still can't make it run as how I want.

- (void)isHeadsetPluggedIn {

    UInt32 routeSize = sizeof (CFStringRef);
    CFStringRef route;

    AudioSessionGetProperty (kAudioSessionProperty_AudioRoute,
                             &routeSize,
                             &route);

    NSString* routeStr = (NSString*)route;

    NSRange headsetRange = [routeStr rangeOfString : @"Headset"];
    NSRange receiverRange = [routeStr rangeOfString : @"Receiver"];

    if(headsetRange.location != NSNotFound) {
        // Don't change the route if the headset is plugged in.
        NSLog(@"headphone is plugged in ");
          //here is the place i want to play music
          /* AVAudioPlayer *mySound;

    mySound =[[AVAudioPlayer alloc]initWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"apple_SIMToolkitPositiveACK" withExtension:@"mp3" ]error:nil];
    [mySound play];

//here is the place where i must receive the info about plug-in(headset)
*/
    }
    else if (receiverRange.location != NSNotFound) {
        // Change to play on the speaker
        NSLog(@"play on the speaker");

    }
    else {
        NSLog(@"Unknown audio route.");

    }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
ilhan çetin
  • 383
  • 5
  • 19
  • [Some](http://stackoverflow.com/questions/2520296/how-can-i-find-out-if-an-external-headset-is-connected-to-an-iphone) [other](http://stackoverflow.com/questions/667196/detecting-iphone-ipod-touch-accessories) [people](http://stackoverflow.com/questions/1832041/how-to-programatically-detect-earpiece-in-iphone) asked for this before. And there are posted solutions. – Youssef Oct 15 '12 at 14:56
  • @ender i couldnt find any solution on those links-i hadd seen them before asking. – ilhan çetin Oct 16 '12 at 08:07

0 Answers0