我正在使用 AVAssetReader 和 AVAssetReaderTrackOutput 从 iOS 上的 iPod 库中读取音频资产。但是,当我读取数据并将块重新组合在一起时,文件并不完全相同。缺少几 kB,因此无法播放音频文件。
这是我用来提取音频数据的代码
// Copy next audio samples
CMSampleBufferRef buffer = [[reader_.outputs objectAtIndex:0] copyNextSampleBuffer];
// Extract bytes from buffer
CMBlockBufferRef dataBuffer = CMSampleBufferGetDataBuffer(buffer);
size_t bufLen = CMBlockBufferGetDataLength(dataBuffer);
UInt8 buf[bufLen];
CMBlockBufferCopyDataBytes(dataBuffer, 0, bufLen, buf);
// Pass data to delegate
if ([delegate respondsToSelector:@selector(assetStream:hasDataAvailable:)]) {
[delegate assetStream:self hasDataAvailable:[NSData dataWithBytes:buf length:bufLen]];
}
// Invalidate buffer
CMSampleBufferInvalidate(buffer);
我在这里做错了什么?