Handled FLAC seeking to the end of file, and stopping on seek errors in general
parent
104e4c140f
commit
9d5a1fc32e
|
@ -117,6 +117,7 @@
|
||||||
void *inputBuffer = malloc(CHUNK_SIZE);
|
void *inputBuffer = malloc(CHUNK_SIZE);
|
||||||
|
|
||||||
BOOL shouldClose = YES;
|
BOOL shouldClose = YES;
|
||||||
|
BOOL seekError = NO;
|
||||||
|
|
||||||
while ([self shouldContinue] == YES && [self endOfStream] == NO)
|
while ([self shouldContinue] == YES && [self endOfStream] == NO)
|
||||||
{
|
{
|
||||||
|
@ -126,7 +127,7 @@
|
||||||
BOOL isPaused = [output isPaused];
|
BOOL isPaused = [output isPaused];
|
||||||
if ( !isPaused ) [output pause];
|
if ( !isPaused ) [output pause];
|
||||||
DLog(@"SEEKING!");
|
DLog(@"SEEKING!");
|
||||||
[decoder seek:seekFrame];
|
seekError = [decoder seek:seekFrame] < 0;
|
||||||
if ( !isPaused ) [output resume];
|
if ( !isPaused ) [output resume];
|
||||||
shouldSeek = NO;
|
shouldSeek = NO;
|
||||||
DLog(@"Seeked! Resetting Buffer");
|
DLog(@"Seeked! Resetting Buffer");
|
||||||
|
@ -141,7 +142,7 @@
|
||||||
int framesToRead = (CHUNK_SIZE - amountInBuffer)/bytesPerFrame;
|
int framesToRead = (CHUNK_SIZE - amountInBuffer)/bytesPerFrame;
|
||||||
int framesRead = [decoder readAudio:((char *)inputBuffer) + amountInBuffer frames:framesToRead];
|
int framesRead = [decoder readAudio:((char *)inputBuffer) + amountInBuffer frames:framesToRead];
|
||||||
|
|
||||||
if (framesRead > 0)
|
if (framesRead > 0 && !seekError)
|
||||||
{
|
{
|
||||||
amountInBuffer += (framesRead * bytesPerFrame);
|
amountInBuffer += (framesRead * bytesPerFrame);
|
||||||
[self writeData:inputBuffer amount:amountInBuffer];
|
[self writeData:inputBuffer amount:amountInBuffer];
|
||||||
|
|
|
@ -262,7 +262,8 @@ void ErrorCallback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorS
|
||||||
|
|
||||||
- (long)seek:(long)sample
|
- (long)seek:(long)sample
|
||||||
{
|
{
|
||||||
FLAC__stream_decoder_seek_absolute(decoder, sample);
|
if (!FLAC__stream_decoder_seek_absolute(decoder, sample))
|
||||||
|
return -1;
|
||||||
|
|
||||||
return sample;
|
return sample;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue