Skip to content

Commit

Permalink
stop using shoutcast metadata and start using API + Pusher
Browse files Browse the repository at this point in the history
  • Loading branch information
maddox committed Apr 10, 2012
1 parent 285f306 commit b69f4c1
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions Play Item/PLAItemAppDelegate.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
// //


#import "PLAItemAppDelegate.h" #import "PLAItemAppDelegate.h"
#import "PLAController.h"
#import "PLATrack.h"
//#import "SPMediaKeyTap.h" //#import "SPMediaKeyTap.h"


@interface PLAItemAppDelegate () @interface PLAItemAppDelegate ()
Expand Down Expand Up @@ -53,6 +55,22 @@ -(void)awakeFromNib{
} }


- (void)applicationDidFinishLaunching:(NSNotification *)aNotification{ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification{

[PLAController sharedController];


// listen for notifications for updated songs from the CFController and pusher
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateWithTrackInformation) name:@"PLANowPlayingUpdated" object:nil];

[PLATrack currentTrackWithBlock:^(PLATrack *track) {
[[PLAController sharedController] setCurrentlyPlayingTrack:track];

dispatch_async(dispatch_get_main_queue(), ^(void) {
[self updateWithTrackInformation];
});

}];



// self.keyTap = [[[SPMediaKeyTap alloc] initWithDelegate:self] autorelease]; // self.keyTap = [[[SPMediaKeyTap alloc] initWithDelegate:self] autorelease];
// [self.keyTap startWatchingMediaKeys]; // [self.keyTap startWatchingMediaKeys];
Expand Down Expand Up @@ -87,7 +105,6 @@ - (IBAction)toggelPlayState{
[self destroyStreamer]; [self destroyStreamer];
[self setPlayActionTitle:@"Play"]; [self setPlayActionTitle:@"Play"];
[statusItem setImage:[NSImage imageNamed:@"status-icon-off.png"]]; [statusItem setImage:[NSImage imageNamed:@"status-icon-off.png"]];
[self setPlayStatus:@""];
}else{ }else{
[self createStreamer]; [self createStreamer];
[self setPlayStatus:@"Buffering..."]; [self setPlayStatus:@"Buffering..."];
Expand All @@ -109,13 +126,10 @@ - (void)createStreamer{


[self destroyStreamer]; [self destroyStreamer];


NSURL *url = [NSURL URLWithString:@"http://play.githubapp.com:8000/listen"]; NSURL *url = [NSURL URLWithString:@"http://localhost:8000/listen"];
streamer = [[AudioStreamer alloc] initWithURL:url]; streamer = [[AudioStreamer alloc] initWithURL:url];


[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackStateChanged:) name:ASStatusChangedNotification object:streamer]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackStateChanged:) name:ASStatusChangedNotification object:streamer];
#ifdef SHOUTCAST_METADATA
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(metadataChanged:) name:ASUpdateMetadataNotification object:streamer];
#endif
} }


- (void)destroyStreamer{ - (void)destroyStreamer{
Expand All @@ -138,6 +152,7 @@ - (void)playbackStateChanged:(NSNotification *)aNotification{
}else if ([streamer isPlaying]){ }else if ([streamer isPlaying]){
[self setPlayActionTitle:@"Stop"]; [self setPlayActionTitle:@"Stop"];
[statusItem setImage:[NSImage imageNamed:@"status-icon-on.png"]]; [statusItem setImage:[NSImage imageNamed:@"status-icon-on.png"]];
[self updateWithTrackInformation];
}else if ([streamer isPaused]){ }else if ([streamer isPaused]){
[self setPlayActionTitle:@"Play"]; [self setPlayActionTitle:@"Play"];
[self setPlayStatus:@""]; [self setPlayStatus:@""];
Expand All @@ -149,26 +164,13 @@ - (void)playbackStateChanged:(NSNotification *)aNotification{
} }
} }


#ifdef SHOUTCAST_METADATA - (void)updateWithTrackInformation{
- (void)metadataChanged:(NSNotification *)aNotification{ PLATrack *currentlyPlayingTrack = [[PLAController sharedController] currentlyPlayingTrack];
//NSLog(@"Raw meta data = %@", [[aNotification userInfo] objectForKey:@"metadata"]);
NSArray *metaParts = [[[aNotification userInfo] objectForKey:@"metadata"] componentsSeparatedByString:@";"]; NSString *playStatusString = [NSString stringWithFormat:@"%@ - %@ - %@", [currentlyPlayingTrack artist], [currentlyPlayingTrack album], [currentlyPlayingTrack name]];
NSString *item;

NSMutableDictionary *hash = [[NSMutableDictionary alloc] init];
for (item in metaParts) {
// split the key/value pair
NSArray *pair = [item componentsSeparatedByString:@"='"];
// don't bother with bad metadata
if ([pair count] == 2)
[hash setObject:[pair objectAtIndex:1] forKey:[pair objectAtIndex:0]];
}


// do something with the StreamTitle [self setPlayStatus:playStatusString];
NSString *streamString = [[hash objectForKey:@"StreamTitle"] stringByReplacingOccurrencesOfString:@"'" withString:@""];
[self setPlayStatus:streamString];
} }
#endif




#pragma mark - #pragma mark -
Expand Down

0 comments on commit b69f4c1

Please sign in to comment.