I am reading audio resources from the iPod library on iOS using AVAssetReader and AVAssetReaderTrackOutput. However, when I read the data and return the pieces, the file is not exactly the same. Several kB are absent, and therefore the sound file does not play.
Here is the code that I use to extract audio data
CMSampleBufferRef buffer = [[reader_.outputs objectAtIndex:0] copyNextSampleBuffer];
CMBlockBufferRef dataBuffer = CMSampleBufferGetDataBuffer(buffer);
size_t bufLen = CMBlockBufferGetDataLength(dataBuffer);
UInt8 buf[bufLen];
CMBlockBufferCopyDataBytes(dataBuffer, 0, bufLen, buf);
if ([delegate respondsToSelector:@selector(assetStream:hasDataAvailable:)]) {
[delegate assetStream:self hasDataAvailable:[NSData dataWithBytes:buf length:bufLen]];
}
CMSampleBufferInvalidate(buffer);
What am I doing wrong here?
source
share