这是我在这里的第一篇文章,希望你能帮助我。我正在处理此代码以获取基于 AudioQueue 的 AAC 播放,我用 WAV 格式对其进行了测试,它可以工作。当我放一个.CAF 或 .M4A文件,然后我触发播放方法,出现此错误:
错误:>aq> 1608:失败 (-66674);将停止(66150/0 帧)
我一直在Apple的开发支持文档中搜索此错误代码-66674,并说我有一个涉及AudioQueuePrime或AudioQueueStart问题的错误(现在AudioQueuePrime不在代码上,但我也一直在测试这个)。我知道可以使用带有音频队列的AAC,就我而言,我相信这是准确同步声音的最可靠方法。
- (IBAction)play:(id)sender {
//OSStatus result;
NSArray *audioTracks = [NSArray arrayWithObjects:
@"/Users/mauro_ptt/Documents/XCODE/SimpleAQPlayViewController/Sample01.caf",
nil];
for (id object in audioTracks) {
// Open the audio file from an existing NSString path
NSURL *sndFileURL = [NSURL fileURLWithPath:object];
AudioFileOpenURL((__bridge CFURLRef)sndFileURL, kAudioFileReadPermission, 0, &mAudioFile);
// get audio format
UInt32 dataFormatSize = sizeof(mDataFormat);
AudioFileGetProperty(mAudioFile, kAudioFilePropertyDataFormat, &dataFormatSize, &mDataFormat);
// create playback queue
AudioQueueNewOutput(&mDataFormat, AQOutputCallback, (__bridge void *)(self), CFRunLoopGetCurrent(), kCFRunLoopCommonModes, 0, &mQueue);
// get buffer size, number of packets to read
UInt32 maxPacketSize;
UInt32 propertySize = sizeof(maxPacketSize);
// get the theoretical max packet size without scanning the entire file
AudioFileGetProperty(mAudioFile, kAudioFilePropertyPacketSizeUpperBound, &propertySize, &maxPacketSize);
// get sizes for up to 0.5 seconds of audio
DeriveBufferSize(mDataFormat, maxPacketSize, 0.5, &bufferByteSize, &mNumPacketsToRead);
// allocate packet descriptions array
bool isFormatVBR = (mDataFormat.mBytesPerPacket == 0 || mDataFormat.mFramesPerPacket == 0);
if (isFormatVBR) {
mPacketsDescs = (AudioStreamPacketDescription*) malloc(mNumPacketsToRead * sizeof(AudioStreamPacketDescription));
} else {
mPacketsDescs = NULL;
}
// Get magic cookie (COMPRESSED AAC)
UInt32 cookieSize = sizeof(UInt32);
OSStatus couldNotGetProperty = AudioFileGetPropertyInfo(mAudioFile, kAudioFilePropertyMagicCookieData, &cookieSize, NULL);
if ((couldNotGetProperty == noErr) && cookieSize) {
char *magicCookie = (char *) malloc(cookieSize);
AudioFileGetProperty(mAudioFile, kAudioFilePropertyMagicCookieData, &cookieSize, magicCookie);
AudioQueueSetProperty(mQueue, kAudioQueueProperty_MagicCookie, magicCookie, cookieSize);
free(magicCookie);
}
// Allocate and prime audio queue buffers
mCurrentPacket = 0;
for (int i=0; i < kNumberBuffers; ++i) {
AudioQueueAllocateBuffer(mQueue, bufferByteSize, &mBuffers[i]);
AQOutputCallback((__bridge void *)(self), mQueue, mBuffers[i]);
}
mIsRunning = true;
AudioQueueStart(mQueue, NULL);
}
}
提前感谢!
是关于 AQOutputCallback 的问题,必须小心在每个函数参数上放置正确的类型。
一个月前我遇到了类似的问题,但我无法弄清楚。所以最终使用了.wav。尺寸更大,但幸运的是我只需要播放 5 个文件。