如果检测耳机插入iPhone [英] Detecting if headphones are plugged into iPhone

查看:167
本文介绍了如果检测耳机插入iPhone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道,如果你能检测是否耳机插入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.

感谢

推荐答案

http://developer.apple.com/iphone/library/sample$c$c/SpeakHere/Introduction/Intro.html

在这个项目中有一个code-片段,如果耳机是unpluged它暂停录制。也许你可以用它来实现你的结果。

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.

祝你好运!

(编辑)

您将不得不学习的SpeakHereController.mm文件。结果
我发现在这个code中的 awakeFromNib

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);

这篇关于如果检测耳机插入iPhone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆