diff --git a/Audio/AudioPlayer.m b/Audio/AudioPlayer.m index c720bf783..2ce5558cd 100644 --- a/Audio/AudioPlayer.m +++ b/Audio/AudioPlayer.m @@ -62,6 +62,7 @@ [self waitUntilCallbacksExit]; if(output) { [output setShouldContinue:NO]; + [output close]; } if(!output) { output = [[OutputNode alloc] initWithController:self previous:nil]; @@ -136,6 +137,7 @@ } if(output) { [output setShouldContinue:NO]; + [output close]; } output = nil; } diff --git a/Audio/Chain/OutputNode.m b/Audio/Chain/OutputNode.m index c03d82d32..dc128bb8f 100644 --- a/Audio/Chain/OutputNode.m +++ b/Audio/Chain/OutputNode.m @@ -156,10 +156,6 @@ } - (void)setShouldContinue:(BOOL)s { - if(output && !s) { - [output stop]; - } - [super setShouldContinue:s]; // if (s == NO) diff --git a/Audio/Output/OutputAVFoundation.m b/Audio/Output/OutputAVFoundation.m index b0fb55a80..d6b3b2621 100644 --- a/Audio/Output/OutputAVFoundation.m +++ b/Audio/Output/OutputAVFoundation.m @@ -301,7 +301,9 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons } - (BOOL)signalEndOfStream:(double)latency { + stopped = YES; BOOL ret = [outputController selectNextBuffer]; + stopped = ret; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(NSEC_PER_SEC * latency)), dispatch_get_main_queue(), ^{ [self->outputController endOfInputPlayed]; [self->outputController resetAmountPlayed]; @@ -1009,9 +1011,7 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons - (void)doStop { if(stopInvoked) { - while(!stopCompleted) { - usleep(5000); - } + stopFlush = NO; return; } @synchronized(self) { @@ -1060,7 +1060,7 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons compareVal = CMTimeCompare(outputPts, currentPts); [currentPtsLock unlock]; usleep(5000); - } while(compareVal > 0); + } while(stopFlush && compareVal > 0); } [self removeSynchronizerBlock]; [renderSynchronizer setRate:0];