gpt4 book ai didi

ios - iOS (Objective-C) 在 AudioQueue 中播放 AAC 文件的问题

转载 作者:行者123 更新时间:2023-11-29 03:13:28 26 4
gpt4 key购买 nike

这是我在这里的第一篇文章,我希望你能帮助我。我正在处理这段代码以获得基于 AudioQueue 的 AAC 播放,我用 WAV 格式测试了它,它可以工作。当我放入 .CAF 或 .M4A 文件然后触发播放方法时,会发生此错误:

ERROR: >aq> 1608: failed (-66674); will stop (66150/0 frames)

我一直在 Apple 的开发支持文档中搜索此错误代码 -66674,并说我有一个涉及 AudioQueuePrime 或 AudioQueueStart 问题的错误(现在 AudioQueuePrime 不在代码中,但我一直在测试这个还)。我知道可以使用带 AudioQueues 的 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 的问题,必须小心将正确的类型放在每个函数参数上。

关于ios - iOS (Objective-C) 在 AudioQueue 中播放 AAC 文件的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21962742/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com