Skip to content

Commit

Permalink
Integrated Mac and iPhone versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Gallagher committed Jun 17, 2009
1 parent 6d0a846 commit c061aa3
Show file tree
Hide file tree
Showing 20 changed files with 7,919 additions and 32 deletions.
1 change: 0 additions & 1 deletion Classes/AudioStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ typedef enum
AS_STOPPING_EOF,
AS_STOPPING_USER_ACTION,
AS_STOPPING_ERROR,
AS_STOPPING_END_OF_PRESCAN,
AS_STOPPING_TEMPORARILY
} AudioStreamerStopReason;

Expand Down
44 changes: 44 additions & 0 deletions Classes/AudioStreamer.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ - (void)handleBufferCompleteForQueue:(AudioQueueRef)inAQ
buffer:(AudioQueueBufferRef)inBuffer;
- (void)handlePropertyChangeForQueue:(AudioQueueRef)inAQ
propertyID:(AudioQueuePropertyID)inID;

#ifdef TARGET_OS_IPHONE
- (void)handleInterruptionChangeToState:(AudioQueuePropertyID)inInterruptionState;
#endif

- (void)enqueueBuffer;
- (void)handleReadFromStream:(CFReadStreamRef)aStream
eventType:(CFStreamEventType)eventType;
Expand Down Expand Up @@ -327,6 +331,12 @@ + (NSString *)stringForErrorCode:(AudioStreamerErrorCode)anErrorCode
return AS_GET_AUDIO_TIME_FAILED_STRING;
case AS_NETWORK_CONNECTION_FAILED:
return AS_NETWORK_CONNECTION_FAILED_STRING;
case AS_AUDIO_QUEUE_STOP_FAILED:
return AS_AUDIO_QUEUE_STOP_FAILED_STRING;
case AS_AUDIO_STREAMER_FAILED:
return AS_AUDIO_STREAMER_FAILED_STRING;
default:
return AS_AUDIO_STREAMER_FAILED_STRING;
}

return AS_AUDIO_STREAMER_FAILED_STRING;
Expand Down Expand Up @@ -584,6 +594,7 @@ - (BOOL)openFileStream
kCFStreamPropertyHTTPShouldAutoredirect,
kCFBooleanTrue) == false)
{
#ifdef TARGET_OS_IPHONE
UIAlertView *alert =
[[UIAlertView alloc]
initWithTitle:NSLocalizedStringFromTable(@"File Error", @"Errors", nil)
Expand All @@ -597,6 +608,20 @@ - (BOOL)openFileStream
withObject:nil
waitUntilDone:YES];
[alert release];
#else
NSAlert *alert =
[NSAlert
alertWithMessageText:NSLocalizedStringFromTable(@"File Error", @"Errors", nil)
defaultButton:NSLocalizedString(@"OK", @"")
alternateButton:nil
otherButton:nil
informativeTextWithFormat:NSLocalizedStringFromTable(@"Unable to configure network read stream.", @"Errors", nil)];
[alert
performSelector:@selector(runModal)
onThread:[NSThread mainThread]
withObject:nil
waitUntilDone:NO];
#endif
return NO;
}

Expand Down Expand Up @@ -624,6 +649,7 @@ - (BOOL)openFileStream
if (!CFReadStreamOpen(stream))
{
CFRelease(stream);
#ifdef TARGET_OS_IPHONE
UIAlertView *alert =
[[UIAlertView alloc]
initWithTitle:NSLocalizedStringFromTable(@"File Error", @"Errors", nil)
Expand All @@ -637,6 +663,20 @@ - (BOOL)openFileStream
withObject:nil
waitUntilDone:YES];
[alert release];
#else
NSAlert *alert =
[NSAlert
alertWithMessageText:NSLocalizedStringFromTable(@"File Error", @"Errors", nil)
defaultButton:NSLocalizedString(@"OK", @"")
alternateButton:nil
otherButton:nil
informativeTextWithFormat:NSLocalizedStringFromTable(@"Unable to configure network read stream.", @"Errors", nil)];
[alert
performSelector:@selector(runModal)
onThread:[NSThread mainThread]
withObject:nil
waitUntilDone:NO];
#endif
return NO;
}

Expand Down Expand Up @@ -821,6 +861,8 @@ - (void)start
}
else if (state == AS_INITIALIZED)
{
NSAssert([[NSThread currentThread] isEqual:[NSThread mainThread]],
@"Playback can only be started from the main thread.");
notificationCenter =
[[NSNotificationCenter defaultCenter] retain];
self.state = AS_STARTING_FILE_THREAD;
Expand Down Expand Up @@ -1547,6 +1589,7 @@ - (void)handlePropertyChangeForQueue:(AudioQueueRef)inAQ
[pool release];
}

#ifdef TARGET_OS_IPHONE
//
// handleInterruptionChangeForQueue:propertyID:
//
Expand All @@ -1567,6 +1610,7 @@ - (void)handleInterruptionChangeToState:(AudioQueuePropertyID)inInterruptionStat
[self pause];
}
}
#endif

@end

Expand Down
33 changes: 33 additions & 0 deletions Classes/MacStreamingPlayerController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// MacStreamingPlayerController.h
// MacStreamingPlayer
//
// Created by Matt Gallagher on 28/10/08.
// Copyright Matt Gallagher 2008. All rights reserved.
//
// Permission is given to use this source code file, free of charge, in any
// project, commercial or otherwise, entirely at your risk, with the condition
// that any redistribution (in part or whole) of source code must retain
// this copyright and permission notice. Attribution in compiled projects is
// appreciated but not required.
//

#import <Cocoa/Cocoa.h>

@class AudioStreamer;

@interface MacStreamingPlayerController : NSObject
{
IBOutlet NSTextField *downloadSourceField;
IBOutlet NSButton *button;
IBOutlet NSTextField *positionLabel;
AudioStreamer *streamer;
NSTimer *progressUpdateTimer;
}

- (IBAction)buttonPressed:(id)sender;
- (void)spinButton;
- (void)updateProgress:(NSTimer *)aNotification;

@end

Loading

0 comments on commit c061aa3

Please sign in to comment.