View Full Version : Playing sounds

Jun 29, 2011, 08:27 PM
I thought I would add some dice rolling sounds to my dice application but everything I find online is directed towards iphone. Is it the same process for a standard OS X app?

Any doc's or where to look for this would be much appreciated.


Jun 29, 2011, 10:00 PM
Try NSSound. I've written a Mac bouncing ball app (not on the Mac App Store) that picks a song to play in the background. Each song is just an .aif file that I put in the Xcode project.

[NSSound soundNamed:@"MySong.aif"];

There's more that needs to get done to get this to play.

If you're looking for a die roll sound the above might work (think of the die roll sound as a very short sound). But someone else may have a better way.

Jun 29, 2011, 10:51 PM
Thanks, I will read up on NSSound tonight and take another step in learning.


Jun 29, 2011, 11:41 PM
Cool, I got the sound to play when the dice roll button is clicked. But I am getting this weird result. I have a NSSlider that sets the minimum number that can be rolled, ie, 1 to 100 or 34 to 100, as an example. But that slider is also acting like a volume control. The higher the value the louder the roll?

In the @interface I just have NSSound * sound; and Method deceleration.


sound = [[NSSound alloc] initWithContentsOfFile: @"/Users/larspro/diceRollSound.aif" byReference:YES];
[sound play];

How could that slider even be connected to the audio?


Jun 29, 2011, 11:46 PM
NEVER MIND! I found out the problem. I guess my degree in sound engineering paid off tonight. I placed the [self playAudio]; in the loop section with the dice. So every time the dice had to re roll to get above that number ir played the sound again, each iteration would amplifying the sound. Had nothing to do with the slider.