diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..b1073cb Binary files /dev/null and b/.DS_Store differ diff --git a/Audjustable.xcodeproj/project.xcworkspace/xcuserdata/tum.xcuserdatad/UserInterfaceState.xcuserstate b/Audjustable.xcodeproj/project.xcworkspace/xcuserdata/tum.xcuserdatad/UserInterfaceState.xcuserstate index a8c1c95..ca3d5d4 100644 Binary files a/Audjustable.xcodeproj/project.xcworkspace/xcuserdata/tum.xcuserdatad/UserInterfaceState.xcuserstate and b/Audjustable.xcodeproj/project.xcworkspace/xcuserdata/tum.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Audjustable/Classes/AudioPlayer/AudioPlayer.h b/Audjustable/Classes/AudioPlayer/AudioPlayer.h index 023a912..7ef491b 100644 --- a/Audjustable/Classes/AudioPlayer/AudioPlayer.h +++ b/Audjustable/Classes/AudioPlayer/AudioPlayer.h @@ -153,8 +153,10 @@ AudioQueueBufferRefLookupEntry; int packetsFilled; int fillBufferIndex; - + +#if TARGET_OS_IPHONE UIBackgroundTaskIdentifier backgroundTaskId; +#endif AudioPlayerErrorCode errorCode; AudioPlayerStopReason stopReason; diff --git a/Audjustable/Classes/AudioPlayer/AudioPlayer.m b/Audjustable/Classes/AudioPlayer/AudioPlayer.m index 0b60148..bbeacb1 100644 --- a/Audjustable/Classes/AudioPlayer/AudioPlayer.m +++ b/Audjustable/Classes/AudioPlayer/AudioPlayer.m @@ -456,6 +456,7 @@ static void AudioQueueIsRunningCallbackProc(void* userData, AudioQueueRef audioQ free(audioQueueBufferLookup); } +#if TARGET_OS_IPHONE -(void) startSystemBackgroundTask { pthread_mutex_lock(&playerMutex); @@ -474,7 +475,9 @@ static void AudioQueueIsRunningCallbackProc(void* userData, AudioQueueRef audioQ } pthread_mutex_unlock(&playerMutex); } +#endif +#if TARGET_OS_IPHONE -(void) stopSystemBackgroundTask { pthread_mutex_lock(&playerMutex); @@ -488,6 +491,7 @@ static void AudioQueueIsRunningCallbackProc(void* userData, AudioQueueRef audioQ } pthread_mutex_unlock(&playerMutex); } +#endif -(DataSource*) dataSourceFromURL:(NSURL*)url { @@ -554,8 +558,9 @@ static void AudioQueueIsRunningCallbackProc(void* userData, AudioQueueRef audioQ { pthread_mutex_lock(&playerMutex); { +#if TARGET_OS_IPHONE [self startSystemBackgroundTask]; - +#endif [self clearQueue]; [upcomingQueue enqueue:[[QueueEntry alloc] initWithDataSource:dataSourceIn andQueueItemId:queueItemId]]; @@ -1003,8 +1008,10 @@ static void AudioQueueIsRunningCallbackProc(void* userData, AudioQueueRef audioQ -(void) createAudioQueue { OSStatus error; - + +#if TARGET_OS_IPHONE [self startSystemBackgroundTask]; +#endif if (audioQueue) { @@ -1583,18 +1590,22 @@ static void AudioQueueIsRunningCallbackProc(void* userData, AudioQueueRef audioQ if (error) { +#if TARGET_OS_IPHONE if (backgroundTaskId == UIBackgroundTaskInvalid) { [self startSystemBackgroundTask]; } +#endif [self stopAudioQueue]; [self createAudioQueue]; AudioQueueStart(audioQueue, NULL); } - + +#if TARGET_OS_IPHONE [self stopSystemBackgroundTask]; +#endif return YES; } diff --git a/README.md b/README.md index 36ae07d..aaeb53a 100644 --- a/README.md +++ b/README.md @@ -37,5 +37,9 @@ audioPlayer.delegate = self; ``` +## Other + +Background playback on iOS is easily added to your application by using the `AudioSessionInitialize` to your AppDelegate. + ### Authors and Contributors Copyright 2012, Thong Nguyen (@tumtumtum) \ No newline at end of file