【问题标题】:Get notification using NSDistributedNotificationCenter for iTunes on song info change使用 NSDistributedNotificationCenter for iTunes 获取有关歌曲信息更改的通知
【发布时间】:2011-08-16 07:05:19
【问题描述】:

我知道您可以使用[iTunesDNC addObserver:self selector:@selector(updateInfo:) name:@"com.apple.iTunes.playerInfo" object:nil]; 在播放器每次更改歌曲/停止/播放/等时收到通知。但我需要的是每次在 iTunes 上更改信息(例如更改歌曲标题、更改歌词、艺术家等)时的通知

有什么建议吗?我很确定我只需要将 com.apple.iTunes.playerInfo 更改为不是 playerInfo 的其他内容。

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

谢谢!

【问题讨论】:

    标签: objective-c cocoa notifications itunes


    【解决方案1】:

    是的,有办法。每次更改歌曲信息时,iTunes 都会发布一条“com.apple.iTunes.sourceSaved”通知,其 userInfo 字典是用户的库。

    您可以通过收听发布到分布式通知中心的每个通知来查看 iTunes 发送的此通知和其他通知。

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

    【讨论】:

    • 老兄,你太棒了,谢谢!哈哈,不仅通过 iTunes 歌曲更改挽救了我的理智(我几乎放弃了),而且检查所有通知的功能......哈哈哈我想知道是否有类似的东西!谢谢!
    • 这不是给你来自所有应用程序的通知,而不仅仅是 iTunes?
    • 是的,如果应用程序向 NSDistributedNotificationCenter 发送通知,它会为您提供所有信息。
    • 您是如何发现com.apple.iTunes.sourceSaved 通知存在的?它是否记录在某处?
    【解决方案2】:
    猜你喜欢
    • 2011-07-30
    • 2016-06-28
    • 2010-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-01
    • 1970-01-01
    相关资源
    最近更新 更多