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

PanzyCat

macrumors newbie
Original poster
Jul 7, 2010
21
0
Hey guys

I was wondering if you could help me with my issue below.

Code:
- (IBAction)playsound1 {

NSString *path = [[NSBundle mainBundle] pathForResource:@"song" ofType:@"wav"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath: path] error:NULL];
[theAudio play];

}
When I press the buttons often, after 200-250 times pressing the buttons, the buttons don't sound anymore. I can continue pressing the buttons, but no sound appears. But the application doesn't break down, i can continue using my application fine, but only the sound doesn't sound anymore, so I have to restart the application and after the restart everything works fine again, till I pressed the sound-buttons 200-250 times and the game begins again. I can't figure out the problem.

If you could help, that would be great.
 
No, sorry. I actually downloaded xcode yesterday, and watched a tutorial on how to make sounds. I wanted to make a little soundboard.

I know that I would release it in the .h file, but I don't know how I would do that?
 
From what I read in the link you just sent me, this is what I believe it should look like.

Code:
- (IBAction)playsound1 {

NSString *path = [[NSBundle mainBundle] pathForResource:@"song" ofType:@"wav"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath: path] error:NULL];
[theAudio play];
[theAudio release];

}
 
From what I read in the link you just sent me, this is what I believe it should look like.

Code:
- (IBAction)playsound1 {

NSString *path = [[NSBundle mainBundle] pathForResource:@"song" ofType:@"wav"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath: path] error:NULL];
[theAudio play];
[theAudio release];

}

I suggest that that will probably not do what you want. You want to release the theAudio when the sound finishes playing. Look at the delegate methods.
 
I suggest that that will probably not do what you want. You want to release the theAudio when the sound finishes playing. Look at the delegate methods.


Is this in the link you sent me?

I get that I have to release theAudio after 1 count. I don't know how to tell it to do that.
 
Code:
	NSString *path = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"wav"];
	AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
	theAudio.delegate = self;
	[theAudio play];
	
	if([theAudio initWithData:audioData error:NULL]) {
        [theAudio autorelease];
    } else {
        [theAudio release];
        theAudio = nil;
    }
    return theAudio;
}


is that right?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.