Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Amigalander

macrumors regular
Original poster
I've just begun learning about Sound, and am having a little trouble in loops.
I'd like to play a system sound every time I go thru a loop. However, the code below plays only once and won't repeat in the loop. What have I done wrong?

Thank you

Code:
tinker = [[NSSound alloc] initWithContentsOfFile: @"/System/Library/Sounds/Tink.aiff" byReference:YES];
for(i = 0; i < 20; i++)
{
	[tinker play];
	usleep(90000);
}
 
Thank you.

So this means an NSSound doesn't "rewind" after playing.

May I ask how you knew this? I mean, is there some part of the Apple docs I am not seeing?
 
I looked at the docs, made a guess and tested it out 🙂

There's probably another way to do it though, since setCurrentTime: is a 10.5 method. I rarely use NSSound, only for playing simple sounds. QTMovie provides much more control.
 
Bah! A guess? Hehe, thanks 🙂

This gets me wondering, am I approaching this totally wrong?

What's the standard way to just play system sounds which are in /System/Library/Sounds? Or is there no "standard" way?
 
I think what you're doing is fine, but it'd be better to use [NSSound soundNamed😡"Tink"] instead of using the file path.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.