【问题标题】:does itunes fire events that other processes on the OS can listen for?iTunes 会触发操作系统上其他进程可以侦听的事件吗?
【发布时间】:2014-06-23 03:39:38
【问题描述】:

我正在考虑创建一个应用程序,该应用程序涉及了解在 iTunes 中播放的歌曲。

如果 iTunes 不触发事件,是否有数据库或某种方式可以通过编程方式获取 iTunes 中正在播放的内容?

【问题讨论】:

  • 你想“监控”什么样的事件?
  • Raptor,它说明了我在我的问题中寻找的内容。我想知道正在播放什么歌曲。因此,要监控的最重要事件是歌曲何时开始或停止。
  • 这可能与此有关:apple.stackexchange.com/a/66052/40962

标签: macos cocoa itunes


【解决方案1】:

iTunes 确实会发送分布式通知。您可以通过观察com.apple.iTunes.playerInfo

获得完整的曲目状态
NSDistributedNotificationCenter.defaultCenter().addObserver(self, selector: "iTunesNotification:", name: "com.apple.iTunes.playerInfo", object: nil)
func iTunesNotification (notification:NSNotification!) {
    var trackInfo:NSDictionary! = notification.userInfo
    println("Track Info \(trackInfo)")
}

轨道的样本输出是:

Track Info {
    Album = "The Very Best Of Sting & The Police";
    "Album Artist" = "Sting & The Police";
    "Album Rating" = 0;
    "Album Rating Computed" = 1;
    Artist = "Sting & The Police";
    "Artwork Count" = 1;
    Composer = Sting;
    Genre = Rock;
    "Library PersistentID" = 3465537150503037139;
    Location = "file://localhost/Users/GoodSpeed/Music/iTunes/iTunes%20Media/Music/Sting%20&%20The%20Police/The%20Very%20Best%20Of%20Sting%20&%20The%20Police/17%20Roxanne.mp3";
    Name = Roxanne;
    PersistentID = 716102833338382931;
    "Play Count" = 1;
    "Play Date" = "2013-12-28 10:43:24 +0000";
    "Player State" = Playing;
    "Playlist PersistentID" = 5080879747404822807;
    "Rating Computed" = 1;
    "Skip Count" = 0;
    "Store URL" = "itms://itunes.com/link?n=Roxanne&an=Sting%20%26%20The%20Police&pn=The%20Very%20Best%20Of%20Sting%20%26%20The%20Police&cn=Sting";
    "Total Time" = 190458;
    "Track Number" = 17;
    Year = 2002;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-26
    • 1970-01-01
    • 2020-09-06
    • 1970-01-01
    • 1970-01-01
    • 2020-05-24
    • 2015-12-18
    相关资源
    最近更新 更多