Change to mimic iTunes to a limited degree instead, hopefully this is enough info for most applications
parent
22e97735c6
commit
540069c019
|
@ -12,18 +12,23 @@
|
||||||
|
|
||||||
#import "AudioScrobbler.h"
|
#import "AudioScrobbler.h"
|
||||||
|
|
||||||
NSString *TrackPlaying = @"com.swinsian.Swinsian-Track-Playing";
|
NSString *TrackNotification = @"com.apple.iTunes.playerInfo";
|
||||||
NSString *TrackStopped = @"com.swinsian.Swinsian-Track-Stopped";
|
|
||||||
NSString *TrackPaused = @"com.swinsian.Swinsian-Track-Paused";
|
|
||||||
|
|
||||||
NSString *TrackArtist = @"artist";
|
NSString *TrackArtist = @"Artist";
|
||||||
NSString *TrackAlbum = @"album";
|
NSString *TrackAlbum = @"Album";
|
||||||
NSString *TrackTitle = @"title";
|
NSString *TrackTitle = @"Name";
|
||||||
NSString *TrackGenre = @"genre";
|
NSString *TrackGenre = @"Genre";
|
||||||
NSString *TrackComposer = @"composer";
|
NSString *TrackNumber = @"Track Number";
|
||||||
NSString *TrackNumber = @"trackNumber";
|
NSString *TrackLength = @"Total Time";
|
||||||
NSString *TrackLength = @"length";
|
NSString *TrackPath = @"Location";
|
||||||
NSString *TrackCurrentTime = @"currentTime";
|
NSString *TrackState = @"Player State";
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
TrackPlaying,
|
||||||
|
TrackPaused,
|
||||||
|
TrackStopped
|
||||||
|
} TrackStatus;
|
||||||
|
|
||||||
@implementation PlaybackEventController
|
@implementation PlaybackEventController
|
||||||
|
|
||||||
|
@ -70,17 +75,29 @@ NSString *TrackCurrentTime = @"currentTime";
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSDictionary *)fillNotificationDictionary:(PlaylistEntry *)pe
|
- (NSDictionary *)fillNotificationDictionary:(PlaylistEntry *)pe status:(TrackStatus)status
|
||||||
{
|
{
|
||||||
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
|
||||||
|
|
||||||
|
[dict setObject:[[pe URL] absoluteString] forKey:TrackPath];
|
||||||
if ([pe title]) [dict setObject:[pe title] forKey:TrackTitle];
|
if ([pe title]) [dict setObject:[pe title] forKey:TrackTitle];
|
||||||
if ([pe artist]) [dict setObject:[pe artist] forKey:TrackArtist];
|
if ([pe artist]) [dict setObject:[pe artist] forKey:TrackArtist];
|
||||||
if ([pe album]) [dict setObject:[pe album] forKey:TrackAlbum];
|
if ([pe album]) [dict setObject:[pe album] forKey:TrackAlbum];
|
||||||
if ([pe genre]) [dict setObject:[pe genre] forKey:TrackGenre];
|
if ([pe genre]) [dict setObject:[pe genre] forKey:TrackGenre];
|
||||||
if ([pe track]) [dict setObject:[NSString stringWithFormat:@"%@",[pe track]] forKey:TrackNumber];
|
if ([pe track]) [dict setObject:[NSString stringWithFormat:@"%@",[pe track]] forKey:TrackNumber];
|
||||||
if ([pe length]) [dict setObject:[pe length] forKey:TrackLength];
|
if ([pe length]) [dict setObject:[NSNumber numberWithInteger:(NSInteger)([[pe length] doubleValue] * 1000.0)] forKey:TrackLength];
|
||||||
if ([pe currentPosition]) [dict setObject:[NSNumber numberWithDouble:[pe currentPosition]] forKey:TrackCurrentTime];
|
|
||||||
|
NSString * state = nil;
|
||||||
|
|
||||||
|
switch (status)
|
||||||
|
{
|
||||||
|
case TrackPlaying: state = @"Playing"; break;
|
||||||
|
case TrackPaused: state = @"Paused"; break;
|
||||||
|
case TrackStopped: state = @"Stopped"; break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
[dict setObject:state forKey:TrackState];
|
||||||
|
|
||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
|
@ -91,7 +108,7 @@ NSString *TrackCurrentTime = @"currentTime";
|
||||||
[entry release];
|
[entry release];
|
||||||
entry = [pe retain];
|
entry = [pe retain];
|
||||||
|
|
||||||
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:TrackPlaying object:nil userInfo:[self fillNotificationDictionary:pe]];
|
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:TrackNotification object:nil userInfo:[self fillNotificationDictionary:pe status:TrackPlaying] deliverImmediately:YES];
|
||||||
|
|
||||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||||
|
|
||||||
|
@ -146,7 +163,7 @@ NSString *TrackCurrentTime = @"currentTime";
|
||||||
|
|
||||||
- (void)performPlaybackDidPauseActions
|
- (void)performPlaybackDidPauseActions
|
||||||
{
|
{
|
||||||
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:TrackPaused object:nil userInfo:[self fillNotificationDictionary:entry]];
|
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:TrackNotification object:nil userInfo:[self fillNotificationDictionary:entry status:TrackPaused] deliverImmediately:YES];
|
||||||
if([[NSUserDefaults standardUserDefaults] boolForKey:@"enableAudioScrobbler"]) {
|
if([[NSUserDefaults standardUserDefaults] boolForKey:@"enableAudioScrobbler"]) {
|
||||||
[scrobbler pause];
|
[scrobbler pause];
|
||||||
}
|
}
|
||||||
|
@ -154,7 +171,7 @@ NSString *TrackCurrentTime = @"currentTime";
|
||||||
|
|
||||||
- (void)performPlaybackDidResumeActions
|
- (void)performPlaybackDidResumeActions
|
||||||
{
|
{
|
||||||
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:TrackPlaying object:nil userInfo:[self fillNotificationDictionary:entry]];
|
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:TrackNotification object:nil userInfo:[self fillNotificationDictionary:entry status:TrackPlaying] deliverImmediately:YES];
|
||||||
if([[NSUserDefaults standardUserDefaults] boolForKey:@"enableAudioScrobbler"]) {
|
if([[NSUserDefaults standardUserDefaults] boolForKey:@"enableAudioScrobbler"]) {
|
||||||
[scrobbler resume];
|
[scrobbler resume];
|
||||||
}
|
}
|
||||||
|
@ -162,7 +179,7 @@ NSString *TrackCurrentTime = @"currentTime";
|
||||||
|
|
||||||
- (void)performPlaybackDidStopActions
|
- (void)performPlaybackDidStopActions
|
||||||
{
|
{
|
||||||
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:TrackStopped object:nil userInfo:[self fillNotificationDictionary:entry]];
|
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:TrackNotification object:nil userInfo:[self fillNotificationDictionary:entry status:TrackStopped] deliverImmediately:YES];
|
||||||
[entry release];
|
[entry release];
|
||||||
entry = nil;
|
entry = nil;
|
||||||
if([[NSUserDefaults standardUserDefaults] boolForKey:@"enableAudioScrobbler"]) {
|
if([[NSUserDefaults standardUserDefaults] boolForKey:@"enableAudioScrobbler"]) {
|
||||||
|
|
Loading…
Reference in New Issue