Note that there are some explanatory texts on larger screens.

plurals
  1. POPlay audio if headset is plugged-in
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/2520296/how-can-i-find-out-if-an-external-headset-is-connected-to-an-iphone">How can I find out if an external headset is connected to an iPhone?</a> </p> </blockquote> <p>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.</p> <p><strong>EDIT</strong> 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.</p> <pre><code>- (void)isHeadsetPluggedIn { UInt32 routeSize = sizeof (CFStringRef); CFStringRef route; AudioSessionGetProperty (kAudioSessionProperty_AudioRoute, &amp;routeSize, &amp;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."); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload