我正在寻找一些Objective-c代码,它向NSLog输出当前MacOSX系统上每个可用Sound资源的名称。我做了很多谷歌搜索。我错过了一些关键术语,因为搜索没有任何有用的东西。 只要我知道来自How do I play a sound in Mac OS?的声音的名称,我就有代码正在播放声音。
// Assumes #import <AppKit/AppKit.h> and the framework has been added.
NSSound *sound = [[NSSound alloc] initWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"Fark" ofType:@"mp3"] byReference:NO];
[sound play];
[sound release];
答案 0 :(得分:1)
查看+[NSSound soundNamed:]
的文档,您会发现该方法将在查看应用程序的主要包后搜索以下目录:
~/Library/Sounds
/Library/Sounds
/Network/Library/Sounds
/System/Library/Sounds
因此,这些可能是寻找机器上可用系统声音的好地方。
“当前MacOSX系统上的每个可用声音资源”都是一个相当高的顺序,具体取决于您的意思。系统声音可能会在上述目录中找到,但在应用程序中可能还有声音,您可能会或可能不会认为它们是操作系统的一部分。