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

nickculbertson

macrumors regular
Original poster
Nov 19, 2010
226
0
Nashville, TN
I'm stuck. I can play an audio file with the AVAudioplayer but I can't find a way to release the audio when the audio is played again without a clipping sound.

Code:
- (IBAction)playSound1:(id)sender {
	NSString *path = [[NSBundle mainBundle] pathForResource:@"sound1" ofType:@"wav"];
	if(theAudio)[theAudio release];
	theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
	[theAudio play];
}

My short term solution was to lower the volume of the first sound which works but doesn't release the audio.

Code:
- (IBAction)playSound1:(id)sender {
	NSString *path = [[NSBundle mainBundle] pathForResource:@"sound1" ofType:@"wav"];
	if(theAudio)theAudio.volume -= .99;
	theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
	[theAudio play];
}

How can I release the first audio when the action is called a second time?

Thanks,
Nick
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.