获取通知使用NSDistributedNotificationCenter for iTunes的歌曲信息更改 [英] Get notification using NSDistributedNotificationCenter for iTunes on song info change

查看:332
本文介绍了获取通知使用NSDistributedNotificationCenter for iTunes的歌曲信息更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道你可以使用 [iTunesDNC addObserver:self selector:@selector(updateInfo :) name:@com.apple.iTunes.playerInfoobject:nil]; 每次播放器更改歌曲/停止/播放/等时获得通知。但是我需要的是每次在iTunes上更改信息时发出通知(例如歌曲标题改变,歌词改变,艺术家等)。

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)

有任何建议吗?我很确定我只需要改变 com.apple.iTunes.playerInfo 不是 playerInfo

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

我知道这应该是可行的,因为有一个名为 SongGenie ,如果您在iTunes上编辑歌曲的ID3标签或添加歌词,它将更改其信息。

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.

谢谢!

推荐答案

是的,有一种方法。每次更改歌曲信息时,iTunes会发布一个 com.apple.iTunes.sourceSaved 通知,其userInfo字典是用户的音乐库。

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.

可以通过监听发布到分布式通知中心的每个通知来检查iTunes和其他通知。

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);
}

这篇关于获取通知使用NSDistributedNotificationCenter for iTunes的歌曲信息更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆