Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added readonly access to the AudioStreamer's stop reason

Fixed iOS 3 Compatability by checking for background task support
  • Loading branch information...
commit 545e5e238d1451c5595b34ebf3fee0e06aba40eb 1 parent 44a5689
@bradfordcp bradfordcp authored
Showing with 22 additions and 16 deletions.
  1. +1 −0  Classes/AudioStreamer.h
  2. +21 −16 Classes/AudioStreamer.m
View
1  Classes/AudioStreamer.h
@@ -183,6 +183,7 @@ extern NSString * const ASUpdateMetadataNotification;
@property AudioStreamerErrorCode errorCode;
@property (readonly) AudioStreamerState state;
+@property (readonly) AudioStreamerStopReason stopReason;
@property (readonly) double progress;
@property (readonly) double bufferFillPercentage;
@property (readonly) double duration;
View
37 Classes/AudioStreamer.m
@@ -226,6 +226,7 @@ @implementation AudioStreamer
@synthesize errorCode;
@synthesize state;
+@synthesize stopReason;
@synthesize bitRate;
@synthesize httpHeaders;
@synthesize numberOfChannels;
@@ -1237,8 +1238,12 @@ - (void)pause
else if (state == AS_PAUSED)
{
err = AudioQueueStart(audioQueue, NULL);
-#if TARGET_OS_IPHONE
- bgTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
+#if TARGET_OS_IPHONE
+ if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)]) {
+ if (bgTaskId != UIBackgroundTaskInvalid) {
+ bgTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
+ }
+ }
#endif
if (err)
{
@@ -1834,7 +1839,9 @@ - (void)enqueueBuffer
{
err = AudioQueueStart(audioQueue, NULL);
#if TARGET_OS_IPHONE
- bgTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
+ if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)]) {
+ bgTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
+ }
#endif
if (err)
{
@@ -1848,8 +1855,10 @@ - (void)enqueueBuffer
self.state = AS_WAITING_FOR_QUEUE_TO_START;
err = AudioQueueStart(audioQueue, NULL);
-#if TARGET_OS_IPHONE
- bgTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
+#if TARGET_OS_IPHONE
+ if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)]) {
+ bgTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
+ }
#endif
if (err)
{
@@ -2338,9 +2347,6 @@ - (void)handlePropertyChangeForQueue:(AudioQueueRef)inAQ
propertyID:(AudioQueuePropertyID)inID
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-#if TARGET_OS_IPHONE
- UIBackgroundTaskIdentifier newTaskId = UIBackgroundTaskInvalid;
-#endif
@synchronized(self)
{
if (inID == kAudioQueueProperty_IsRunning)
@@ -2365,21 +2371,20 @@ - (void)handlePropertyChangeForQueue:(AudioQueueRef)inAQ
// By creating an NSRunLoop for the AudioQueue thread, it changes the
// thread destruction order and seems to avoid this crash bug -- or
// at least I haven't had it since (nasty hard to reproduce error!)
- //
-#if TARGET_OS_IPHONE
- newTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
-#endif
+ //
[NSRunLoop currentRunLoop];
self.state = AS_PLAYING;
#if TARGET_OS_IPHONE
- if (bgTaskId != UIBackgroundTaskInvalid) {
- [[UIApplication sharedApplication] endBackgroundTask: bgTaskId];
+ if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)]) {
+ if (bgTaskId != UIBackgroundTaskInvalid) {
+ [[UIApplication sharedApplication] endBackgroundTask: bgTaskId];
+ }
+
+ bgTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
}
-
- bgTaskId = newTaskId;
#endif
}
else
Please sign in to comment.
Something went wrong with that request. Please try again.