【发布时间】:2014-06-04 12:47:47
【问题描述】:
在我的 iOS 应用程序中,我使用 AudioQueue 进行音频录制和播放,基本上我在 iOS 上运行并移植了 OSX 版本。
我意识到在 iOS 中我需要配置/设置 AV 会话,到目前为止我已经完成了以下操作,
-(void)initAudioSession{
//get your app's audioSession singleton object
AVAudioSession* session = [AVAudioSession sharedInstance];
//error handling
BOOL success;
NSError* error;
//set the audioSession category.
//Needs to be Record or PlayAndRecord to use audioRouteOverride:
success = [session setCategory:AVAudioSessionCategoryPlayAndRecord
error:&error];
if (!success) NSLog(@"AVAudioSession error setting category:%@",error);
//set the audioSession override
success = [session overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker
error:&error];
if (!success) NSLog(@"AVAudioSession error overrideOutputAudioPort:%@",error);
//activate the audio session
success = [session setActive:YES error:&error];
if (!success) NSLog(@"AVAudioSession error activating: %@",error);
else NSLog(@"audioSession active");
}
现在发生的事情是,Speaker AudioQueue 回调永远不会被调用,我检查了很多答案,cmets on so ,google 等...看起来是正确的,我做的方式是
- 为输入和输出创建音频队列:配置线性 PCM,16000 采样率
- 分配缓冲区
- 使用有效回调设置队列,
- 开始队列,
似乎很好,我可以听到另一端的输出(即 Input AudioQueue 正在工作)但输出 AudioQueue(即 AudioQueueOutputCallback 永远不会被调用)。
我怀疑我需要设置正确的 AVSessionCatogery,我正在尝试使用所有可能的选项,但无法在扬声器中听到任何声音,
我将我的实现与在主线程上运行 AudioQueue 的 Apple 示例 Speakhere 进行比较。
即使我不启动 Input AudioQueue ( mic ),我也会有同样的行为。并且很难有 Speakhere 行为,即停止录制和播放
感谢您的关注,期待您的 cmets/帮助。就能分享代码sn -p。
【问题讨论】:
标签: ios objective-c voip audioqueue