我有一个应用程序,我正在考虑创建,这将涉及知道什么歌在iTunes中播放。
如果itunes没有触发事件,是否有数据库或某种方式以编程方式获取在iTunes中播放的内容?
答案 0 :(得分:2)
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;
}