From 195b1bf388aea880f2b37c2239dbac6e7c173bca Mon Sep 17 00:00:00 2001 From: Thong Nguyen Date: Sun, 24 Mar 2013 20:46:17 +0000 Subject: [PATCH] Fix seeking to end of some files might not cause end of file to be notified --- Audjustable/Classes/AudioPlayer/AudioPlayer.m | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/Audjustable/Classes/AudioPlayer/AudioPlayer.m b/Audjustable/Classes/AudioPlayer/AudioPlayer.m index c0347dc..36b26b8 100644 --- a/Audjustable/Classes/AudioPlayer/AudioPlayer.m +++ b/Audjustable/Classes/AudioPlayer/AudioPlayer.m @@ -672,12 +672,9 @@ static void AudioQueueIsRunningCallbackProc(void* userData, AudioQueueRef audioQ } else if (memcmp(¤tAudioStreamBasicDescription, ¤tlyReadingEntry->audioStreamBasicDescription, sizeof(currentAudioStreamBasicDescription)) != 0) { - if (audioPacketsPlayedCount == 0 && audioPacketsReadCount == 0) + if (currentlyReadingEntry == currentlyPlayingEntry) { - NSLog(@"CreateAudioQueue"); - [self createAudioQueue]; - [self setInternalState:AudioPlayerInternalStateWaitingForData]; } else { @@ -925,7 +922,7 @@ static void AudioQueueIsRunningCallbackProc(void* userData, AudioQueueRef audioQ } } - if (signal) + if (signal || YES) { pthread_cond_signal(&queueBufferReadyCondition); } @@ -1543,14 +1540,21 @@ static void AudioQueueIsRunningCallbackProc(void* userData, AudioQueueRef audioQ QueueEntry* entry = [upcomingQueue dequeue]; BOOL startPlaying = currentlyPlayingEntry == nil; + BOOL wasCurrentlyPlayingNothing = currentlyPlayingEntry == nil; [self setCurrentlyReadingEntry:entry andStartPlaying:startPlaying]; + + if (wasCurrentlyPlayingNothing) + { + [self setInternalState:AudioPlayerInternalStateWaitingForData]; + } } else if (currentlyPlayingEntry == nil) { if (self.internalState != AudioPlayerInternalStateStopped) { [self stopAudioQueue]; + stopReason = AudioPlayerStopReasonEof; } } } @@ -1818,7 +1822,7 @@ static void AudioQueueIsRunningCallbackProc(void* userData, AudioQueueRef audioQ } pthread_cond_signal(&queueBufferReadyCondition); - pthread_mutex_unlock(&queueBuffersMutex); + bytesFilled = 0; fillBufferIndex = 0; @@ -1832,6 +1836,8 @@ static void AudioQueueIsRunningCallbackProc(void* userData, AudioQueueRef audioQ audioPacketsReadCount = 0; audioPacketsPlayedCount = 0; audioQueueFlushing = NO; + + pthread_mutex_unlock(&queueBuffersMutex); } -(void) dataSourceDataAvailable:(DataSource*)dataSourceIn @@ -1922,6 +1928,17 @@ static void AudioQueueIsRunningCallbackProc(void* userData, AudioQueueRef audioQ { currentlyReadingEntry.bufferIndex = audioPacketsReadCount; currentlyReadingEntry = nil; + + if (self.internalState == AudioPlayerInternalStatePlaying) + { + if (audioQueue) + { + if (![self audioQueueIsRunning]) + { + [self startAudioQueue]; + } + } + } } else {