gpt4 book ai didi

ios - 中断后我是否需要重置 Audio Session 属性?

转载 作者:行者123 更新时间:2023-12-01 19:07:49 26 4
gpt4 key购买 nike

我正在实现音频 session 中断的C侦听器。当需要中断时,我将停用音频 session 。然后,当我的应用恢复时,我将再次激活音频 session 。我已经为音频 session 设置了许多属性和类别,重新激活后是否需要重置所有设置?

提前致谢。

一些代码供引用:

初始化,设置类别:

OSStatus error = AudioSessionInitialize(NULL, NULL, interuptListenerCallBack, (__bridge void *)(self));
UInt32 category = kAudioSessionCategory_PlayAndRecord;
error = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &category);
if (error) printf("couldn't set audio category!");
//use speaker as default
UInt32 doChangeDefaultOutput = 1;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof(doChangeDefaultOutput), &doChangeDefaultOutput);
//allow bluethoothInput
UInt32 allowBluetoothInput = 1;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryEnableBluetoothInput, sizeof(allowBluetoothInput), &allowBluetoothInput);

使用interuptListenerCallBack可以使我由于中断而停用和响应音频 session ,使用
 OSStatus error = AudioSessionSetActive(false);
if (error) printf("couldn't deactivate audio session!");

要么
  OSStatus error = AudioSessionSetActive(true);
if (error) printf("AudioSessionSetActive (true) failed");

最佳答案

如果正确使用了音频 session 中断侦听器,则否,您不必重置属性。您只需要确保实际调用了kAudioSessionBeginInterruptionkAudioSessionEndInterruption即可。我不确定您的听众是什么样子,但是如果您正在执行以下操作:

if (inInterruptionState == kAudioSessionBeginInterruption) {
AudioSessionSetActive(NO);
}
if (inInterruptionState == kAudioSessionEndInterruption) {

AudioSessionSetActive(YES);
}

并且遵循音频 session 的规则,那么从理论上讲,您不必重置属性。

我不知道您正在使用音频 session 做什么,但是您也可以使用以下命令暂停和恢复播放:
kAudioSessionInterruptionType_ShouldResume 


kAudioSessionInterruptionType_ShouldNotResume.

您可以按照文档中所述使用它们:

kAudioSessionInterruptionType_ShouldResume

Indicates that the interruption that has just ended was one for which it is appropriate to immediately resume playback; for example, an incoming phone call was rejected by the user.

Available in iOS 4.0 and later.

Declared in AudioSession.h.

kAudioSessionInterruptionType_ShouldNotResume

Indicates that the interruption that has just ended was one for which it is not appropriate to resume playback; for example, your app had been interrupted by iPod playback.

Available in iOS 4.0 and later.

Declared in AudioSession.h.



您应该阅读 docs,因为其中有很多有关暂停,恢复和处理AudioSession中断的信息。

注意:

自iOS7起,AudioSession已被弃用。请改用 AVAudioSession方法,或通过设置常量 AVAudioSessionInterruptionOptions AVAudioSessionInterruptionType 来设置“暂停并继续”选项。

(自iOS 6起可用)

关于ios - 中断后我是否需要重置 Audio Session 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18644037/

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