Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get notification using NSDistributedNotificationCenter for iTunes on song info change

I know you can use [iTunesDNC addObserver:self selector:@selector(updateInfo:) name:@"com.apple.iTunes.playerInfo" object:nil]; to get a notification every time the player changes song/stops/plays/etc. But what I need is a notification every time information is changed on iTunes (ex. song title changed, lyrics changed, artist, etc)

Any suggestions? Im pretty sure I just need to change com.apple.iTunes.playerInfo to something else that is not playerInfo.

I know it should be posible, because there is an app called SongGenie that will change its info if you edit a song's ID3 tags on iTunes or add lyrics.

Thank you!

like image 959
Kevin Chavez Avatar asked Dec 12 '22 13:12

Kevin Chavez


1 Answers

Yes, there is a way. Every time song info is changed iTunes posts a "com.apple.iTunes.sourceSaved" notification whose userInfo dictionary is the user's library.

You can check out this and other notifications that iTunes sends by listening to every notificaion posted to the Distributed Notification Center.

 [[NSDistributedNotificationCenter defaultCenter] addObserver:self
                                                  selector:@selector(allDistributedNotifications:)
                                                  name:nil
                                                  object:nil];

- (void) allDistributedNotifications:(NSNotification *)note 
{
    NSString *object = [note object];
    NSString *name = [note name];
    NSDictionary *userInfo = [note userInfo];
    NSLog(@"<%p>%s: object: %@ name: %@ userInfo: %@", self, __PRETTY_FUNCTION__, object, name, userInfo);
}
like image 69
Francis McGrew Avatar answered Jan 19 '23 01:01

Francis McGrew