views:

66

answers:

1

Hey,

Does anyone know if you can detect if headphones are plugged into the iPhone, and if they aren't - disable sound from your application.

I think I could manage disabling sound, but the detection part I have yet to find anything on.

Thanks

+1  A: 

http://developer.apple.com/iphone/library/samplecode/SpeakHere/Introduction/Intro.html

In this project there is a code-snippet where it pauses recording if the headphones is unpluged. Maybe you can use it to achieve your result.

Good luck!

(edit)

You will have to study the SpeakHereController.mm file.
I found this code in the awakeFromNib method

// we do not want to allow recording if input is not available
error = AudioSessionGetProperty(kAudioSessionProperty_AudioInputAvailable, &size, &inputAvailable);
if (error) printf("ERROR GETTING INPUT AVAILABILITY! %d\n", error);
btn_record.enabled = (inputAvailable) ? YES : NO;

// we also need to listen to see if input availability changes
error = AudioSessionAddPropertyListener(kAudioSessionProperty_AudioInputAvailable, propListener, self);
if (error) printf("ERROR ADDING AUDIO SESSION PROP LISTENER! %d\n", error);
hellozimi
Thanks, I'll have a look at that! :)
ing0