ios - 检测耳机是否已插入 iOS 设备
<p><p>ios 设备上有互动电影。当电影开始时(点击),视频开头的人会问你插入耳机,如果插入,那么视频应该自动跳转到故事(直接进入视频故事)。我应该怎么办?以及如何编写代码?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>首先,您必须注册 AudioRoute Changes:-</p>
<pre><code>AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange,
audioRouteChangeListenerCallback,
self);
</code></pre>
<p>在这里您可以描述更改路线的原因:-</p>
<pre><code>CFDictionaryRef routeChangeDictionary = inPropertyValue;
CFNumberRef routeChangeReasonRef =
CFDictionaryGetValue (routeChangeDictionary,
CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
SInt32 routeChangeReason;
CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable)
{
// your statements for headset unplugged
}
if (routeChangeReason == kAudioSessionRouteChangeReason_NewDeviceAvailable)
{
// your statements for headset plugged
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 检测耳机是否已插入 iOS 设备,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/10685313/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/10685313/
</a>
</p>
页:
[1]