How to programmatically get iTunes settings to search for audio libraries?

I am building a Mac application 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 from iTunes. How can I get directory paths from iTunes? Will it be in some kind of preference setting?

Thank.

+3
source share
3 answers

For those who will encounter this problem in the future, I have documented the approach I used below.

I decided not to use the framework of Karelia, because I do not need all the bells and whistles. I just need to find the iTunes library and display a list of songs.

Karelia, , , iTunes , .

+ (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 .

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

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

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

, iApps , .

iMovie
iPhotoAutoImportPath
iPhotoRecentDatabases
iTunesRecentDatabases
iTunesRecentDatabasePaths
+7

. , , iTunes . . . ( ) iTunes (, ).

:

NSString *musicPath = [NSSearchPathForDirectoriesInDomains(NSMusicDirectory, NSUserDomainMask, YES) objectAtIndex:0];

iTunes, "iTunes Music Library.xml", iTunes . , iTunes , , .

+3

, iTunes. iTunes ; , .

, Karelia Software iMedia Browser, iTunes .

, , , Finder Get Info . ; , Info.plist.

+1

Source: https://habr.com/ru/post/1785690/


All Articles