diff --git a/StreamingKit/StreamingKit/STKAudioPlayer.m b/StreamingKit/StreamingKit/STKAudioPlayer.m index adc8663..7e3a4e4 100644 --- a/StreamingKit/StreamingKit/STKAudioPlayer.m +++ b/StreamingKit/StreamingKit/STKAudioPlayer.m @@ -530,7 +530,12 @@ static void AudioFileStreamPacketsProc(void* clientData, UInt32 numberBytes, UIn { currentlyPlayingEntry.dataSource.delegate = nil; [currentlyReadingEntry.dataSource unregisterForEvents]; + + OSSpinLockLock(¤tEntryReferencesLock); + currentlyPlayingEntry = nil; + + OSSpinLockUnlock(¤tEntryReferencesLock); } [self stopAudioUnitWithReason:STKAudioPlayerStopReasonDisposed]; @@ -928,20 +933,15 @@ static void AudioFileStreamPacketsProc(void* clientData, UInt32 numberBytes, UIn } OSSpinLockLock(¤tEntryReferencesLock); - STKQueueEntry* entry = currentlyPlayingEntry; + OSSpinLockUnlock(¤tEntryReferencesLock); if (entry == nil) { - OSSpinLockUnlock(¤tEntryReferencesLock); - - return 0; + return 0; } double retval = [entry duration]; - - OSSpinLockUnlock(¤tEntryReferencesLock); - double progress = [self progress]; if (retval < progress && retval > 0) @@ -964,7 +964,9 @@ static void AudioFileStreamPacketsProc(void* clientData, UInt32 numberBytes, UIn return 0; } + OSSpinLockLock(¤tEntryReferencesLock); STKQueueEntry* entry = currentlyPlayingEntry; + OSSpinLockUnlock(¤tEntryReferencesLock); if (entry == nil) { diff --git a/StreamingKit/StreamingKit/STKQueueEntry.m b/StreamingKit/StreamingKit/STKQueueEntry.m index 1e27973..2b6de04 100644 --- a/StreamingKit/StreamingKit/STKQueueEntry.m +++ b/StreamingKit/StreamingKit/STKQueueEntry.m @@ -18,6 +18,8 @@ { if (self = [super init]) { + self->spinLock = OS_SPINLOCK_INIT; + self.dataSource = dataSourceIn; self.queueItemId = queueItemIdIn; self->lastFrameQueued = -1;