Skip to content

Commit c061aa3

Browse files
author
Matt Gallagher
committed
Integrated Mac and iPhone versions.
1 parent 6d0a846 commit c061aa3

20 files changed

+7919
-32
lines changed

Classes/AudioStreamer.h

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ typedef enum
4444
AS_STOPPING_EOF,
4545
AS_STOPPING_USER_ACTION,
4646
AS_STOPPING_ERROR,
47-
AS_STOPPING_END_OF_PRESCAN,
4847
AS_STOPPING_TEMPORARILY
4948
} AudioStreamerStopReason;
5049

Classes/AudioStreamer.m

+44
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ - (void)handleBufferCompleteForQueue:(AudioQueueRef)inAQ
5555
buffer:(AudioQueueBufferRef)inBuffer;
5656
- (void)handlePropertyChangeForQueue:(AudioQueueRef)inAQ
5757
propertyID:(AudioQueuePropertyID)inID;
58+
59+
#ifdef TARGET_OS_IPHONE
5860
- (void)handleInterruptionChangeToState:(AudioQueuePropertyID)inInterruptionState;
61+
#endif
62+
5963
- (void)enqueueBuffer;
6064
- (void)handleReadFromStream:(CFReadStreamRef)aStream
6165
eventType:(CFStreamEventType)eventType;
@@ -327,6 +331,12 @@ + (NSString *)stringForErrorCode:(AudioStreamerErrorCode)anErrorCode
327331
return AS_GET_AUDIO_TIME_FAILED_STRING;
328332
case AS_NETWORK_CONNECTION_FAILED:
329333
return AS_NETWORK_CONNECTION_FAILED_STRING;
334+
case AS_AUDIO_QUEUE_STOP_FAILED:
335+
return AS_AUDIO_QUEUE_STOP_FAILED_STRING;
336+
case AS_AUDIO_STREAMER_FAILED:
337+
return AS_AUDIO_STREAMER_FAILED_STRING;
338+
default:
339+
return AS_AUDIO_STREAMER_FAILED_STRING;
330340
}
331341

332342
return AS_AUDIO_STREAMER_FAILED_STRING;
@@ -584,6 +594,7 @@ - (BOOL)openFileStream
584594
kCFStreamPropertyHTTPShouldAutoredirect,
585595
kCFBooleanTrue) == false)
586596
{
597+
#ifdef TARGET_OS_IPHONE
587598
UIAlertView *alert =
588599
[[UIAlertView alloc]
589600
initWithTitle:NSLocalizedStringFromTable(@"File Error", @"Errors", nil)
@@ -597,6 +608,20 @@ - (BOOL)openFileStream
597608
withObject:nil
598609
waitUntilDone:YES];
599610
[alert release];
611+
#else
612+
NSAlert *alert =
613+
[NSAlert
614+
alertWithMessageText:NSLocalizedStringFromTable(@"File Error", @"Errors", nil)
615+
defaultButton:NSLocalizedString(@"OK", @"")
616+
alternateButton:nil
617+
otherButton:nil
618+
informativeTextWithFormat:NSLocalizedStringFromTable(@"Unable to configure network read stream.", @"Errors", nil)];
619+
[alert
620+
performSelector:@selector(runModal)
621+
onThread:[NSThread mainThread]
622+
withObject:nil
623+
waitUntilDone:NO];
624+
#endif
600625
return NO;
601626
}
602627

@@ -624,6 +649,7 @@ - (BOOL)openFileStream
624649
if (!CFReadStreamOpen(stream))
625650
{
626651
CFRelease(stream);
652+
#ifdef TARGET_OS_IPHONE
627653
UIAlertView *alert =
628654
[[UIAlertView alloc]
629655
initWithTitle:NSLocalizedStringFromTable(@"File Error", @"Errors", nil)
@@ -637,6 +663,20 @@ - (BOOL)openFileStream
637663
withObject:nil
638664
waitUntilDone:YES];
639665
[alert release];
666+
#else
667+
NSAlert *alert =
668+
[NSAlert
669+
alertWithMessageText:NSLocalizedStringFromTable(@"File Error", @"Errors", nil)
670+
defaultButton:NSLocalizedString(@"OK", @"")
671+
alternateButton:nil
672+
otherButton:nil
673+
informativeTextWithFormat:NSLocalizedStringFromTable(@"Unable to configure network read stream.", @"Errors", nil)];
674+
[alert
675+
performSelector:@selector(runModal)
676+
onThread:[NSThread mainThread]
677+
withObject:nil
678+
waitUntilDone:NO];
679+
#endif
640680
return NO;
641681
}
642682

@@ -821,6 +861,8 @@ - (void)start
821861
}
822862
else if (state == AS_INITIALIZED)
823863
{
864+
NSAssert([[NSThread currentThread] isEqual:[NSThread mainThread]],
865+
@"Playback can only be started from the main thread.");
824866
notificationCenter =
825867
[[NSNotificationCenter defaultCenter] retain];
826868
self.state = AS_STARTING_FILE_THREAD;
@@ -1547,6 +1589,7 @@ - (void)handlePropertyChangeForQueue:(AudioQueueRef)inAQ
15471589
[pool release];
15481590
}
15491591

1592+
#ifdef TARGET_OS_IPHONE
15501593
//
15511594
// handleInterruptionChangeForQueue:propertyID:
15521595
//
@@ -1567,6 +1610,7 @@ - (void)handleInterruptionChangeToState:(AudioQueuePropertyID)inInterruptionStat
15671610
[self pause];
15681611
}
15691612
}
1613+
#endif
15701614

15711615
@end
15721616

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// MacStreamingPlayerController.h
3+
// MacStreamingPlayer
4+
//
5+
// Created by Matt Gallagher on 28/10/08.
6+
// Copyright Matt Gallagher 2008. All rights reserved.
7+
//
8+
// Permission is given to use this source code file, free of charge, in any
9+
// project, commercial or otherwise, entirely at your risk, with the condition
10+
// that any redistribution (in part or whole) of source code must retain
11+
// this copyright and permission notice. Attribution in compiled projects is
12+
// appreciated but not required.
13+
//
14+
15+
#import <Cocoa/Cocoa.h>
16+
17+
@class AudioStreamer;
18+
19+
@interface MacStreamingPlayerController : NSObject
20+
{
21+
IBOutlet NSTextField *downloadSourceField;
22+
IBOutlet NSButton *button;
23+
IBOutlet NSTextField *positionLabel;
24+
AudioStreamer *streamer;
25+
NSTimer *progressUpdateTimer;
26+
}
27+
28+
- (IBAction)buttonPressed:(id)sender;
29+
- (void)spinButton;
30+
- (void)updateProgress:(NSTimer *)aNotification;
31+
32+
@end
33+

0 commit comments

Comments
 (0)