gpt4 book ai didi

ios - iPad 错误处理路由更改扬声器 -> 耳机

转载 作者:行者123 更新时间:2023-11-29 13:49:08 27 4
gpt4 key购买 nike

我运行的是 iOS 4.3.2。

  1. 我在我的 iPad 上启动我的应用程序(没有插入电源)。
  2. 音频作品。
  3. 我插入耳机。
  4. 没有音频,iPad 和耳机都没有。
  5. 我拔下耳机,转到 (2)

或者:

  1. 我在插入耳机的情况下在 iPad 上启动我的应用程序。
  2. 音频从耳机中传出。
  3. 我拔下耳机。
  4. 现在音频来自 iPad。
  5. 我插入耳机。
  6. 没有音频,iPad 和耳机都没有。
  7. 我再次拔下耳机,转到 (4)。

这是我的 Audio Session 代码:

@implementation AudioSession

+ (void) CreateAudioSessionWithInterruptionListener: (AudioSessionInterruptionListener) interruptionListener
returningSampleRate: (Float64 *) pHWSampleRate
{
OSStatus result = AudioSessionInitialize(NULL, NULL, interruptionListener, self);
if (result != kAudioSessionNoError)
{
NSLog(@"AudioSessionInitialize(...) failed!");
return;
}

SET_PROPERTY( kAudioSessionProperty_AudioCategory, UInt32, kAudioSessionCategory_PlayAndRecord );
SET_PROPERTY( kAudioSessionProperty_OverrideCategoryMixWithOthers, UInt32, (UInt32) YES );
SET_PROPERTY( kAudioSessionProperty_PreferredHardwareIOBufferDuration, Float32, .005 );

// GET not set h/w sampleRate
// Float64 hwSampleRate;
// UInt32 size = sizeof(Float64);
AssertOK(AudioSessionGetProperty(
kAudioSessionProperty_CurrentHardwareSampleRate,
& (UInt32) { sizeof(Float64) },
pHWSampleRate),
@"couldn't get hw sample rate");
//NSAssert(size == sizeof(Float64);
NSLog(@"H/W SampleRate: %d", (int) (* pHWSampleRate));

AssertOK(AudioSessionSetActive(true),
@"couldn't set audio session active\n");
}

最佳答案

这实际上可能是一个 iOS 错误。切换到 HDMI 输出(也是 iOS 4.3)时,我遇到了同样的问题。在 50% 的所有情况下,路由更改成功并且音频从电视而不是 iPad 中传出,正如预期的那样。在所有其他 50% 的情况下,插入 HDMI 适配器后,我根本没有音频,既没有电视,也没有 iPad。再次拔下适配器后,我就恢复了音频。

所以我无法真正为您提供一个很好的解决方案,只能提供一个解决方案。注册音频路由更改(通过为属性 kAudioSessionProperty_AudioRouteChange 设置属性监听器)。当此回调触发时,处理它,例如通过重新初始化所有 Core Audio 的东西。这不是一个很好的解决方案,但却是一个可行的解决方案。

更新:
在您的特殊情况下,系统的行为与 Apple 所说的行为非常相似。让我引用 Apple 的 iOS 界面指南:

The case for playback is similar but has different outcomes, as shown on the right of the figure. If a user unplugs the headset during playback, your callback should pause the audio. If a user plugs in the headset during playback, your callback should simply allow playback to continue.

所以 Apple 说:从内置扬声器切换到耳机 -> 播放继续。从耳机切换到内置扬声器 -> 播放暂停。根据这句话,这是一种您应该自己实现的行为,而不是系统为您强制执行的行为,但它非常接近您实际看到的行为,不是吗?

关于ios - iPad 错误处理路由更改扬声器 -> 耳机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5818000/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com