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

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

问题描述

我知道你可以使用 [iTunesDNC addObserver:self selector:@selector(updateInfo:) name:@"com.apple.iTunes.playerInfo" object: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天全站免登陆