From 9aed1b082ae9d44c7ea1bcc125d439d6a63dadc3 Mon Sep 17 00:00:00 2001 From: Andrew Kosovich Date: Fri, 14 Feb 2014 13:37:43 +0200 Subject: [PATCH] Ported error handling from the previous Audjustable player. STKDataSource is designed to return values < 0 in case of error, but new STKAudioPlayer doesn't handle that, which causes crash few lines later when calling AudioFileStreamParseBytes with read<0. --- StreamingKit/StreamingKit/STKAudioPlayer.m | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/StreamingKit/StreamingKit/STKAudioPlayer.m b/StreamingKit/StreamingKit/STKAudioPlayer.m index e8a11b1..b9d295d 100644 --- a/StreamingKit/StreamingKit/STKAudioPlayer.m +++ b/StreamingKit/StreamingKit/STKAudioPlayer.m @@ -1470,6 +1470,17 @@ static void AudioFileStreamPacketsProc(void* clientData, UInt32 numberBytes, UIn } } + if (read < 0) + { + // iOS will shutdown network connections if the app is backgrounded (i.e. device is locked when player is paused) + // We try to reopen -- should probably add a back-off protocol in the future + + long long position = currentlyReadingEntry.dataSource.position; + [currentlyReadingEntry.dataSource seekToOffset:position]; + + return; + } + int flags = 0; if (discontinuous)