diff --git a/Audio/AudioPlayer.h b/Audio/AudioPlayer.h index 334e78159..770c6c2b3 100644 --- a/Audio/AudioPlayer.h +++ b/Audio/AudioPlayer.h @@ -26,6 +26,7 @@ id delegate; BOOL outputLaunched; + BOOL endOfInputReached; } - (id)init; diff --git a/Audio/AudioPlayer.m b/Audio/AudioPlayer.m index d5c9f2a69..6f25b8ac4 100644 --- a/Audio/AudioPlayer.m +++ b/Audio/AudioPlayer.m @@ -24,6 +24,7 @@ output = NULL; bufferChain = NULL; outputLaunched = NO; + endOfInputReached = NO; chainQueue = [[NSMutableArray alloc] init]; } @@ -63,6 +64,7 @@ [anObject setShouldContinue:NO]; } [chainQueue removeAllObjects]; + endOfInputReached = NO; if (bufferChain) { @@ -168,10 +170,9 @@ - (void)resetNextStreams { @synchronized (chainQueue) { - NSUInteger count = [chainQueue count]; [chainQueue removeAllObjects]; - if (count) { + if (endOfInputReached) { [self endOfInputReached:bufferChain]; } } @@ -223,15 +224,17 @@ - (BOOL)endOfInputReached:(BufferChain *)sender //Sender is a BufferChain { - BufferChain *newChain = nil; - - nextStreamUserInfo = [sender userInfo]; - [nextStreamUserInfo retain]; //Retained because when setNextStream is called, it will be released!!! - - [self requestNextStream: nextStreamUserInfo]; - newChain = [[BufferChain alloc] initWithController:self]; - @synchronized (chainQueue) { + BufferChain *newChain = nil; + + nextStreamUserInfo = [sender userInfo]; + [nextStreamUserInfo retain]; //Retained because when setNextStream is called, it will be released!!! + + [self requestNextStream: nextStreamUserInfo]; + newChain = [[BufferChain alloc] initWithController:self]; + + endOfInputReached = YES; + BufferChain *lastChain = [chainQueue lastObject]; if (lastChain == nil) { lastChain = bufferChain; @@ -270,8 +273,9 @@ } [self addChainToQueue:newChain]; + + [newChain release]; } - [newChain release]; return YES; } @@ -281,6 +285,8 @@ @synchronized(chainQueue) { if ([chainQueue count] <= 0) { + endOfInputReached = NO; + //End of playlist [self stop];