Language - Objective-C
I'm using the SoundEffect class to play a short sound. I'm using an NSTimer to call a this method:
- (void)count {
count++;
if (count == 16) {
NSBundle *mainBundle = [NSBundle mainBundle];
SoundEffect *soundEffect = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"beep" ofType:@"aif"]];
[soundEffect play];
count = 0;
}
seconds = seconds - 0.0625; // is equal to 1/16th of a second; effectively takes off one second per second
if (seconds == 0) {
[timer invalidate]; // cancels timer
[timer release];
}
[self convertSeconds];
}
(The count thing is just so the sound plays at a certain interval.)
Anyway, everything works fine, but I think it's inefficient to keep allocating and initializing the SoundEffect class every time my timer fires (which is quite often). Is there a way in which I can aloc and init when I press a button to start the timer, and leave it allocated and initialized so all I have to do is [soundEffect play]?
Thanks!