I'm looking for some objective-c code that outputs to NSLog the name of every available Sound resource on the current MacOSX system. I've done lots of google searches. I'm missing some key term as the searches are not turning up anything useful. I've got code working to play a sound as long as I know the name of the sound from 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];
Take a look at the documentation for +[NSSound soundNamed:] and you'll find that that method will search the following directories after looking in the application's main bundle:
~/Library/Sounds
/Library/Sounds
/Network/Library/Sounds
/System/Library/Sounds
So those would probably be good places to look for the system sounds available on your machine.
"every available Sound resource on the current MacOSX system" is a rather tall order, depending on what you mean. The system sounds will likely be found in the directories described above, but there may also be sounds inside applications that you might or might not consider to be part of the operating system.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With