音频队列:AudioQueueStart返回-50 [英] Audio Queue : AudioQueueStart returns -50
问题描述
我正在尝试在GLES应用程序(Unity3d)中编写麦克风功率计模块。
它在UIKit应用程序中工作正常。但是当我整合到我的unity3d项目中时,AudioQueue无法启动属性。调用AudioQueueStart的结果代码总是-50,但-50是什么意思?我在iOS Developer Library中找不到引用。
I'm trying to write a microphone power meter module in a GLES app (Unity3d). It works fine in UIKit application. But when I integrate into my unity3d project, the AudioQueue cannot start property.The result code of calling AudioQueueStart is always -50, but what does -50 mean? I can't find a reference in iOS Developer Library.
我已经搜索过这个问题,并且知道有人在cocos2d应用程序中遇到同样的问题。也许这有一定的相关性。
I have searched about this problem and know someone has the same problem in a cocos2d application. Maybe this has some relevance.
这是我的开始音频队列的代码:
Here is my code for Start Audio Queue:
UInt32 ioDataSize = sizeof(sampleRate);
AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareSampleRate, &ioDataSize, &sampleRate); //returns noErr
format.mSampleRate = sampleRate;
format.mFormatID = kAudioFormatLinearPCM;
format.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
format.mFramesPerPacket = format.mChannelsPerFrame = 1;
format.mBitsPerChannel = 16;
format.mBytesPerPacket = format.mBytesPerFrame = 2;
AudioQueueNewInput(&format, listeningCallback, self, NULL, NULL, 0, &queue); //returns noErr
AudioQueueBufferRef buffers[3];
for (NSInteger i = 0; i < 3; ++i) {
AudioQueueAllocateBuffer(queue, 735, &buffers[i]); //returns noErr
AudioQueueEnqueueBuffer(queue, buffers[i], 0, NULL); //returns noErr
}
levels = (AudioQueueLevelMeterState *)calloc(sizeof(AudioQueueLevelMeterState), format.mChannelsPerFrame);
UInt32 trueValue = true;
AudioQueueSetProperty(queue, kAudioQueueProperty_EnableLevelMetering, &trueValue, sizeof(UInt32)); //returns noErr
AudioQueueStart(queue, NULL); //returns -50
推荐答案
以下适用于我:
添加:
AVAudioSession * session = [AVAudioSession sharedInstance];
if (!session) printf("ERROR INITIALIZING AUDIO SESSION! \n");
else{
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:&nsError];
if (nsError) printf("couldn't set audio category!");
[session setActive:YES error:&nsError];
if (nsError) printf("AudioSession setActive = YES failed");
}
在 AudioQueueStart(myQueue,NULL)之前;
这篇关于音频队列:AudioQueueStart返回-50的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!