开发者

Scan iTunes Library?

I'm working on a Mac app and I need it to scan the users iTunes library. Any idea how I would go about this? T开发者_如何学编程he app would scan the library looking for different song attributes.


To find the actual most recent location of the iTunes library (and not hope for it to be at the default location) read the iTunesRecentDatabases or iTunesRecentDatabasePaths property from ~/Library/Preferences/com.apple.iApps.plist.

NSArray *libraryDatabases = [[[NSUserDefaults standardUserDefaults] persistentDomainForName:@"com.apple.iApps"] objectForKey:@"iTunesRecentDatabases"];
NSURL *libraryURL = (([libraryDatabases count])) ? [NSURL URLWithString:[dbs objectAtIndex:0]] : nil;

For a more advanced code snippet look for parserInstancesForMediaType: in iMedia's IMBiTunesParser.m


For the actual database parsing it is recommended to use a SAX parser, such as NSXMLParser (vs. a tree parser, such as NSXMLDocument or even worse: NSPropertylistSerialization) as some users have librares with up to and sometimes even more than 100,000+ tracks. Using tree parsing or even serialization will seriously slow down and potentially block your app temporarily.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜