AudioQueue 和 iOS4?

发布于 2024-09-07 00:48:50 字数 895 浏览 1 评论 0原文

以下代码过去对我有用。我现在正在尝试使用 iOS4,但没有运气。它正在模拟器中工作,但我在设备本身上听不到任何声音。我首先尝试将一些样本记录到 NSMutableData 变量中,然后尝试回放它们。

我已经尝试过 Apple 的 SpeakHere 示例 - 它可以工作(但它从文件播放 - 而不是内存)。

知道我错过了什么吗?

AudioSessionInitialize(NULL, NULL, NULL, NULL);
UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord; 
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
AudioSessionSetActive(true);

AudioQueueNewOutput(&m_format,&OutputCallback,self,CFRunLoopGetCurrent(), kCFRunLoopCommonModes,0,&m_device);   
AudioQueueBufferRef nBuffer=NULL;
AudioQueueAllocateBuffer(m_device,[data length],&nBuffer);
nBuffer->mAudioDataByteSize=[data length];
[data getBytes:(nBuffer->mAudioData) length:(nBuffer->mAudioDataByteSize)];
AudioQueueEnqueueBuffer(m_device,nBuffer,0,NULL);
AudioQueueStart(m_device,NULL);

The following code used to work for me in the past. I'm trying it now with iOS4 without luck. It is working in the simulator, but I don't hear anything on the device itself. I first try to record few samples into a NSMutableData variable, and then I try to play them back.

I've tried the SpeakHere sample from Apple - which works (but it playbacks from a file - not memory).

Any idea what am I missing?

AudioSessionInitialize(NULL, NULL, NULL, NULL);
UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord; 
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
AudioSessionSetActive(true);

AudioQueueNewOutput(&m_format,&OutputCallback,self,CFRunLoopGetCurrent(), kCFRunLoopCommonModes,0,&m_device);   
AudioQueueBufferRef nBuffer=NULL;
AudioQueueAllocateBuffer(m_device,[data length],&nBuffer);
nBuffer->mAudioDataByteSize=[data length];
[data getBytes:(nBuffer->mAudioData) length:(nBuffer->mAudioDataByteSize)];
AudioQueueEnqueueBuffer(m_device,nBuffer,0,NULL);
AudioQueueStart(m_device,NULL);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦罢 2024-09-14 00:48:50

我可以建议的主要内容是:

(1)确保设备未静音并且音量已调高

(2)检查结果代码。例如:

OSStatus errorCode = AudioQueueNewOutput (...) ;

if ( errorCode ) NSLog ( @"Error: %u" , errorCode ) ;

其他可以为您提供更多信息的东西:

当它应该运行时,尝试调整音量。如果它调整铃声音量,则音频队列无法正确播放和/或设置。如果它调整播放音量,则 AudioQueue 在请求时可能无法获取数据。

作为记录,我有一个在所有设备上的 iOS 4 上使用 AudioQueue 的应用程序,所以我知道它可以工作并且不是一个错误。

坚持下去:AudioQueue 有时会非常非常烦人。

The main things I can suggest are:

(1) make sure the device is not muted and the volume is up

(2) Check the result codes. For instance:

OSStatus errorCode = AudioQueueNewOutput (...) ;

if ( errorCode ) NSLog ( @"Error: %u" , errorCode ) ;

Something else that would give you a little bit more information:

While it is supposed to be running, try adjusting the volume. If it adjusts the ringer volume, the AudioQueue is not playing and/or setup correctly. If it adjusts the playback volume, than the AudioQueue is probably not getting data when it asks for it.

For the record, I have a an application that's using the AudioQueue on iOS 4 on all devices, so I know it works and it's not a bug.

Keep at it: the AudioQueue can be very, very annoying at times.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文