我正在尝试在GLES应用程序(Unity3d)中编写麦克风功率计模块。 它在UIKit应用程序中工作正常。但是当我集成到我的unity3d项目中时,AudioQueue无法启动属性。调用AudioQueueStart的结果代码总是-50,但-50是什么意思?我在iOS Developer Library中找不到引用。
我已经搜索过这个问题并且知道有人在cocos2d应用程序中遇到了同样的问题。也许这有一定的相关性。
以下是我的启动音频队列代码:
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
答案 0 :(得分:1)
下面适用于我:
添加:
createdon=DESC
之前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");
}
答案 1 :(得分:0)
您是否检查过AudioSession处于AVAudioSessionCategoryRecord或AVAudioSessionCategoryPlayAndRecord模式?