diff --git a/Classes/AudioStreamer.h b/Classes/AudioStreamer.h index 3926f5d..3495fb7 100644 --- a/Classes/AudioStreamer.h +++ b/Classes/AudioStreamer.h @@ -22,7 +22,7 @@ #include #define kNumAQBufs 32 // number of audio queue buffers we allocate -#define kAQBufSize 1024 // number of bytes in each audio queue buffer +#define kAQBufSize 2048 // number of bytes in each audio queue buffer #define kAQMaxPacketDescs 512 // number of packet descriptions in our array typedef enum @@ -69,7 +69,8 @@ typedef enum AS_AUDIO_QUEUE_STOP_FAILED, AS_AUDIO_QUEUE_FLUSH_FAILED, AS_AUDIO_STREAMER_FAILED, - AS_GET_AUDIO_TIME_FAILED + AS_GET_AUDIO_TIME_FAILED, + AS_AUDIO_BUFFER_TOO_SMALL } AudioStreamerErrorCode; extern NSString * const ASStatusChangedNotification; diff --git a/Classes/AudioStreamer.m b/Classes/AudioStreamer.m index b6696c4..45080d5 100644 --- a/Classes/AudioStreamer.m +++ b/Classes/AudioStreamer.m @@ -40,6 +40,7 @@ NSString * const AS_GET_AUDIO_TIME_FAILED_STRING = @"Audio queue get current time failed."; NSString * const AS_AUDIO_STREAMER_FAILED_STRING = @"Audio playback failed"; NSString * const AS_NETWORK_CONNECTION_FAILED_STRING = @"Network connection failed"; +NSString * const AS_AUDIO_BUFFER_TOO_SMALL_STRING = @"Audio packets are larger than kAQBufSize."; @interface AudioStreamer () @property (readwrite) AudioStreamerState state; @@ -335,6 +336,8 @@ + (NSString *)stringForErrorCode:(AudioStreamerErrorCode)anErrorCode return AS_AUDIO_QUEUE_STOP_FAILED_STRING; case AS_AUDIO_STREAMER_FAILED: return AS_AUDIO_STREAMER_FAILED_STRING; + case AS_AUDIO_BUFFER_TOO_SMALL: + return AS_AUDIO_BUFFER_TOO_SMALL_STRING; default: return AS_AUDIO_STREAMER_FAILED_STRING; } @@ -388,7 +391,7 @@ - (void)failWithErrorCode:(AudioStreamerErrorCode)anErrorCode UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:NSLocalizedStringFromTable(@"Audio Error", @"Errors", nil) - message:NSLocalizedStringFromTable(@"Attempt to play streaming audio failed.", @"Errors", nil) + message:NSLocalizedStringFromTable([AudioStreamer stringForErrorCode:self.errorCode], @"Errors", nil) delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil] @@ -405,7 +408,7 @@ - (void)failWithErrorCode:(AudioStreamerErrorCode)anErrorCode defaultButton:NSLocalizedString(@"OK", @"") alternateButton:nil otherButton:nil - informativeTextWithFormat:@"Attempt to play streaming audio failed."]; + informativeTextWithFormat:[AudioStreamer stringForErrorCode:self.errorCode]]; [alert performSelector:@selector(runModal) onThread:[NSThread mainThread] @@ -726,16 +729,18 @@ - (void)startInternal @synchronized(self) { - if (state == AS_STOPPING) + if (state != AS_STARTING_FILE_THREAD) { + if (state != AS_STOPPING && + state != AS_STOPPED) + { + NSLog(@"### Not starting audio thread. State code is: %ld", state); + } self.state = AS_INITIALIZED; [pool release]; return; } - NSAssert(state == AS_STARTING_FILE_THREAD, - @"Start illegally invoked on an audio stream that has already started."); - #ifdef TARGET_OS_IPHONE // // Set the audio session category so that we continue to play if the @@ -1373,6 +1378,7 @@ - (void)handleAudioPackets:(const void *)inInputData { SInt64 packetOffset = inPacketDescriptions[i].mStartOffset; SInt64 packetSize = inPacketDescriptions[i].mDataByteSize; + size_t bufSpaceRemaining; @synchronized(self) { @@ -1391,11 +1397,18 @@ - (void)handleAudioPackets:(const void *)inInputData { return; } + + if (packetSize > kAQBufSize) + { + [self failWithErrorCode:AS_AUDIO_BUFFER_TOO_SMALL]; + } + + bufSpaceRemaining = kAQBufSize - bytesFilled; } // if the space remaining in the buffer is not enough for this packet, then enqueue the buffer. - size_t bufSpaceRemaining = kAQBufSize - bytesFilled; - if (bufSpaceRemaining < packetSize) { + if (bufSpaceRemaining < packetSize) + { [self enqueueBuffer]; } diff --git a/Classes/MacStreamingPlayerController.m b/Classes/MacStreamingPlayerController.m index 2b2e58d..92393af 100644 --- a/Classes/MacStreamingPlayerController.m +++ b/Classes/MacStreamingPlayerController.m @@ -131,7 +131,7 @@ - (void)spinButton CABasicAnimation *animation; animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; animation.fromValue = [NSNumber numberWithFloat:0.0]; - animation.toValue = [NSNumber numberWithFloat:2 * M_PI]; + animation.toValue = [NSNumber numberWithFloat:-2 * M_PI]; animation.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionLinear]; animation.delegate = self; [button.layer addAnimation:animation forKey:@"rotationAnimation"]; diff --git a/Info.plist b/Info.plist deleted file mode 100644 index 71715a2..0000000 --- a/Info.plist +++ /dev/null @@ -1,30 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleDisplayName - ${PRODUCT_NAME} - CFBundleExecutable - ${EXECUTABLE_NAME} - CFBundleIconFile - - CFBundleIdentifier - com.mattgallagher.${PRODUCT_NAME:identifier} - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - ${PRODUCT_NAME} - CFBundlePackageType - APPL - CFBundleSignature - ???? - CFBundleVersion - 1.0 - LSRequiresIPhoneOS - - NSMainNibFile - MainWindow - - diff --git a/Resources/MainWindow.xib b/Resources/MainWindow.xib deleted file mode 100644 index e3d2c31..0000000 --- a/Resources/MainWindow.xib +++ /dev/null @@ -1,206 +0,0 @@ - - - - 528 - 9E17 - 672 - 949.33 - 352.00 - - YES - - - - YES - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - YES - - IBFilesOwner - - - IBFirstResponder - - - - iPhoneStreamingPlayerViewController - - - - - 292 - {320, 480} - - 1 - MSAxIDEAA - - NO - NO - - - - - - YES - - - delegate - - - - 4 - - - - viewController - - - - 11 - - - - window - - - - 14 - - - - - YES - - 0 - - YES - - - - - - -1 - - - RmlsZSdzIE93bmVyA - - - 3 - - - iPhoneStreamingPlayer App Delegate - - - -2 - - - - - 10 - - - - - 12 - - - - - - - YES - - YES - -1.CustomClassName - -2.CustomClassName - 10.CustomClassName - 10.IBEditorWindowLastContentRect - 10.IBPluginDependency - 12.IBEditorWindowLastContentRect - 12.IBPluginDependency - 3.CustomClassName - 3.IBPluginDependency - - - YES - UIApplication - UIResponder - iPhoneStreamingPlayerViewController - {{512, 351}, {320, 480}} - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - {{525, 346}, {320, 480}} - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - iPhoneStreamingPlayerAppDelegate - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - - YES - - YES - - - YES - - - - - YES - - YES - - - YES - - - - 14 - - - - YES - - iPhoneStreamingPlayerAppDelegate - NSObject - - YES - - YES - viewController - window - - - YES - iPhoneStreamingPlayerViewController - UIWindow - - - - IBProjectSource - Classes/iPhoneStreamingPlayerAppDelegate.h - - - - iPhoneStreamingPlayerAppDelegate - NSObject - - IBUserSource - - - - - iPhoneStreamingPlayerViewController - UIViewController - - IBProjectSource - Classes/iPhoneStreamingPlayerViewController.h - - - - - 0 - iPhoneStreamingPlayer.xcodeproj - 3 - - diff --git a/Resources/iPhoneStreamingPlayerViewController.xib b/Resources/iPhoneStreamingPlayerViewController.xib deleted file mode 100644 index b393e54..0000000 --- a/Resources/iPhoneStreamingPlayerViewController.xib +++ /dev/null @@ -1,383 +0,0 @@ - - - - 528 - 9J61 - 677 - 949.46 - 353.00 - - YES - - - - YES - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - YES - - YES - - - YES - - - - YES - - IBFilesOwner - - - IBFirstResponder - - - - 274 - - YES - - - 292 - {{20, 49}, {280, 31}} - - NO - NO - 0 - http://202.6.74.107:8060/triplej.mp3 - 3 - - 3 - MAA - - 2 - - - YES - 1.700000e+01 - - 1 - 3 - - - - - 292 - {{20, 20}, {280, 21}} - - NO - YES - NO - Download URL: - - 1 - MCAwIDAAA - - - 1 - 1.000000e+01 - - - - 292 - {{124, 88}, {72, 73}} - - NO - NO - 0 - 0 - - Helvetica-Bold - 1.500000e+01 - 16 - - - 3 - MQA - - - 1 - MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA - - - 3 - MC41AA - - - NSImage - playbutton.png - - - - - 292 - {{20, 169}, {280, 21}} - - NO - YES - NO - Time Played: - - - 1 - 1.000000e+01 - - - - 292 - {{20, 228}, {280, 21}} - - NO - YES - NO - Volume: - - - 1 - 1.000000e+01 - - - - 292 - {{20, 257}, {280, 55}} - - - 3 - MSAwAA - - NO - - - {320, 460} - - - 1 - MC44NTIwNDA4MyAwLjg1MjA0MDgzIDAuODUyMDQwODMAA - - NO - - - - - - YES - - - view - - - - 7 - - - - button - - - - 28 - - - - buttonPressed: - - - 7 - - 29 - - - - volumeSlider - - - - 36 - - - - downloadSourceField - - - - 38 - - - - positionLabel - - - - 41 - - - - delegate - - - - 44 - - - - - YES - - 0 - - YES - - - - - - -1 - - - RmlsZSdzIE93bmVyA - - - -2 - - - - - 6 - - - YES - - - - - - - - - - - 16 - - - - - 21 - - - - - 23 - - - - - 26 - - - - - 35 - - - YES - - - - - 25 - - - - - - - YES - - YES - -1.CustomClassName - -2.CustomClassName - 16.IBPluginDependency - 21.IBPluginDependency - 23.IBPluginDependency - 25.IBPluginDependency - 26.IBPluginDependency - 35.IBPluginDependency - 6.IBEditorWindowLastContentRect - 6.IBPluginDependency - - - YES - iPhoneStreamingPlayerViewController - UIResponder - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - {{208, 221}, {320, 480}} - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - - YES - - YES - - - YES - - - - - YES - - YES - - - YES - - - - 44 - - - - YES - - iPhoneStreamingPlayerViewController - UIViewController - - buttonPressed: - id - - - YES - - YES - button - downloadSourceField - positionLabel - volumeSlider - - - YES - UIButton - UITextField - UILabel - UIView - - - - IBProjectSource - Classes/iPhoneStreamingPlayerViewController.h - - - - - 0 - iPhoneStreamingPlayer.xcodeproj - 3 - 3.0 - - diff --git a/Resources/loadingbutton.png b/Resources/loadingbutton.png deleted file mode 100644 index 8d13736..0000000 Binary files a/Resources/loadingbutton.png and /dev/null differ diff --git a/Resources/pausebutton.png b/Resources/pausebutton.png deleted file mode 100644 index 3c962bc..0000000 Binary files a/Resources/pausebutton.png and /dev/null differ diff --git a/Resources/playbutton.png b/Resources/playbutton.png deleted file mode 100644 index 76f7d29..0000000 Binary files a/Resources/playbutton.png and /dev/null differ diff --git a/Resources/stopbutton.png b/Resources/stopbutton.png deleted file mode 100644 index fc4482a..0000000 Binary files a/Resources/stopbutton.png and /dev/null differ