How does one play a sound file using Xcode on a Mac OS X.
For example if I want to play the file
test.mp3 on xcode how would I go about doing this?
NSSound *sound = [NSSound soundNamed:@“test.mp3"];
That doesn't seem to work do I have to include something?
Make sure that you drag and drop 'test.mp3' into 'Supporting Files'. I've tested the code and it works.
Cocoa's response is using Objective-C (with the Cocoa API), btw... I don't know what the equivalent would be in C++. I assume there are bindings.
If you want to try out a multi-media, multi-platform library, SFML can play files quite easily.
(see the SFML and Xcode section).
The library you prefer is up to you, but either way you'll have to install something, because C++ by itself has no built-in audio library.
Last edited on
There is no standard way to play a sound file directly.
This will open the default player, you might need to supply the absolute path.
How would you use system on a Mac?
cocaplus, I have moved the mp3 file into a group I created: Supporting Files and it doesn't seem to work, it is giving errors on the code you've given me.
Ganado, idd exactly what you have presented and doesn't seem to work...
>it doesn't seem to work
You need to post the code which 'doesn't work' so that we can see what you are attempting to do.
Please post the error messages.