如何检索的iTunes preferences编程找到音频库? [英] How to retrieve iTunes preferences programmatically to find audio libraries?

查看:186
本文介绍了如何检索的iTunes preferences编程找到音频库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建可可的音频播放Mac上的应用程序。我想我的应用程序来搜索用户计算机上的音频文件的最好的地方是让从iTunes目录路径(S)。我将如何检索从iTunes目录路径(S)?这会不会在某种preference设置的?

I'm creating an application on the Mac in Cocoa that plays audio. I think the best place for my application to search for audio files on a user's computer is to get the directory path(s) from iTunes. How would I retrieve the directory paths(s) from iTunes? Would this be in some sort of preference setting?

感谢。

推荐答案

只是对于那些谁就会在今后遇到这样的问题,我已经证明我下面使用的方法。

Just for those who will encounter this problem in the future, I've documented the approach that I used below.

我决定不使用的卡累利阿框架,因为我并不需要所有的花俏。我只需要找到iTunes资料库,并显示歌曲列表。

I decided not to use the Karelia framework because I don't need all the bells and whistles. I just need to locate the iTunes library and display a list of songs.

我在卡累利阿的框架去了,看来,他们通过用户默认定位iTunes资料库中,如下图所示。

I went through the Karelia framework and it appears that they locate the iTunes library via the user defaults as shown below.

+ (NSArray*) parserInstancesForMediaType:(NSString*)inMediaType
{
    NSMutableArray* parserInstances = [NSMutableArray array];

    if ([self isInstalled])
    {
        CFArrayRef recentLibraries = CFPreferencesCopyAppValue((CFStringRef)@"iTunesRecentDatabases",(CFStringRef)@"com.apple.iApps");
        NSArray* libraries = (NSArray*)recentLibraries;

        for (NSString* library in libraries)
        {
            NSURL* url = [NSURL URLWithString:library];
            NSString* path = [url path];
            BOOL changed;
            (void) [[NSFileManager imb_threadSafeManager] imb_fileExistsAtPath:&path wasChanged:&changed];

            NSString *libraryPath = [path stringByDeletingLastPathComponent];   // folder containing .xml file
            [IMBConfig registerLibraryPath:libraryPath];

            IMBiTunesParser* parser = [[[self class] alloc] initWithMediaType:inMediaType];
            parser.mediaSource = path;
            parser.shouldDisplayLibraryName = libraries.count > 1;
            [parserInstances addObject:parser];
            [parser release];
        }

        if (recentLibraries) CFRelease(recentLibraries);
    }

    return parserInstances;
}

使用上面的方法,你可以找到所有iTunes资料库具有以下code。

Using the above approach, you can locate all iTunes libraries with the following code.

NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSDictionary *userPref = [userDefaults persistentDomainForName:@"com.apple.iApps"];

NSArray *recentDatabases = [userPref objectForKey:@"iTunesRecentDatabases"];

for (NSString *key in recentDatabases)
{
    NSLog(@"%@", key);
}

此外,如果你检查用户默认iApps词典您可以使用这些其他键来获取其它应用信息

Also if you inspect the user defaults iApps dictionary you can use these other keys to get info for other applications

iMovie
iPhotoAutoImportPath
iPhotoRecentDatabases
iTunesRecentDatabases
iTunesRecentDatabasePaths

这篇关于如何检索的iTunes preferences编程找到音频库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆