From 6dccaa4d7fab730c409ac70c384c60e134c3807b Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Sat, 5 Mar 2022 15:53:47 -0800 Subject: [PATCH] Fixes starting playback on short files These two changes fix playback issues with either starting in the middle of the playlist on a really short file terminating immediately instead of queueing more files (InputNode.m), and issues with starting playback at all on the end of a playlist on a short file. (OutputCoreAudio.m) Fixes #246 Signed-off-by: Christopher Snowhill --- Audio/Chain/InputNode.m | 10 ++++++---- Audio/Output/OutputCoreAudio.m | 8 +++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Audio/Chain/InputNode.m b/Audio/Chain/InputNode.m index 950097b4e..4b739248f 100644 --- a/Audio/Chain/InputNode.m +++ b/Audio/Chain/InputNode.m @@ -186,16 +186,18 @@ amountInBuffer = 0; bytesInBuffer = 0; } else { - if(initialBufferFilled == NO) { - [controller initialBufferFilled:self]; - } - DLog(@"End of stream? %@", [self properties]); endOfStream = YES; shouldClose = [controller endOfInputReached]; // Lets us know if we should keep going or not (occassionally, for track changes within a file) DLog(@"closing? is %i", shouldClose); + // Move this here, so that the above endOfInputReached has a chance to queue another track before starting output + // Technically, the output should still play out its buffer first before checking if it should stop + if(initialBufferFilled == NO) { + [controller initialBufferFilled:self]; + } + // wait before exiting, as we might still get seeking request DLog("InputNode: Before wait") [exitAtTheEndOfTheStream waitIndefinitely]; diff --git a/Audio/Output/OutputCoreAudio.m b/Audio/Output/OutputCoreAudio.m index 5cd9833dc..5e0281548 100644 --- a/Audio/Output/OutputCoreAudio.m +++ b/Audio/Output/OutputCoreAudio.m @@ -816,7 +816,13 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.GraphicEQenable"]; [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.eqPreamp"]; } - if(stopNext && started && !paused) { + if(stopNext && !paused) { + if(!started) { + // This happens if playback is started on a very short file, and the queue is empty or at the end of the playlist + started = YES; + NSError *err; + [_au startHardwareAndReturnError:&err]; + } while(![[outputController buffer] isEmpty]) { [writeSemaphore signal]; [readSemaphore signal];