How to retrieve iTunes preferences programmatically to find audio libraries?

后端 未结 3 1424
一生所求
一生所求 2021-02-06 17:56

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 direct

3条回答
  •  说谎
    说谎 (楼主)
    2021-02-06 18:13

    Edit: As others have pointed out, the approach below doesn't address the case that the iTunes library may not be in a user's home folder. See David's answer for a better solution. Finding the user's music folder may still be somewhat useful for finding a standard (though not the only) location of non-iTunes audio files (e.g. as the default folder for an open panel).

    Original answer:

    You could locate the user's Music folder via

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

    This will normally have an iTunes subdirectory that contains the file "iTunes Music Library.xml" which contains most metadata of the user's iTunes library. Don't try to write to it though - iTunes only creates this file so that other apps can access it, but doesn't use it internally otherwise.

提交回复
热议问题