I am trying to implement the AudioFileStreamSeek function in my streaming application. But I can not achieve this. Even Matt Gallagher said on his blog:
By the way, the AudioFileStreamSeek function seems completely broken. If you can't get it to work (like I couldn't) just look for a new point in the file, set the intermittent value to true and let AudioFileStream handle it.
My kindda code looks like this, but I can't get it to work:
NSString *path = [[NSString alloc] initWithContentsOfURL: url];
NSLog(@"url = %@", path);
SInt64 currentOffset;
UInt32 flags = 0;
OSStatus status = AudioFileStreamSeek( audioFileStream, 150, ¤tOffset, &flags );
NSLog(@"Setting next byte offset to: %qi, flags: %d", (long long)currentOffset, flags);
NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath: path];
[fileHandle seekToFileOffset:currentOffset];
NSData * data = [fileHandle readDataOfLength:4096];
NSLog(@"data length %d, bytes %d", [data length], [data bytes]);
if (discontinuous)
{
err = AudioFileStreamParseBytes(audioFileStream, length, bytes, kAudioFileStreamParseFlag_Discontinuity);
if (err)
{
[self failWithErrorCode:AS_FILE_STREAM_PARSE_BYTES_FAILED];
return;
}
}
else
{
err = AudioFileStreamParseBytes(audioFileStream, length, bytes, 0);
if (err)
{
[self failWithErrorCode:AS_FILE_STREAM_PARSE_BYTES_FAILED];
return;
}
}
Please, help...
source
share