Detecting if headphones are plugged into iPhone

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

9
задан ingh.am 26 August 2010 в 13:24
поделиться

1 ответ

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

В этом проекте есть фрагмент кода, в котором запись приостанавливается, если наушники отключены. Может быть, вы можете использовать его для достижения вашего результата.

Удачи!

[править]

Вам придется изучить файл SpeakHereController.mm.
Я нашел этот код в методе awakeFromNib

// 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);
4
ответ дан 4 December 2019 в 11:39
поделиться
Другие вопросы по тегам:

Похожие вопросы: