sound not playing when i press the button and how to fix overlapping sounds
- by alfredjunco
the code is giving me an error"Unused variable'path'" and when i press a button there is no sound playing how do i fix this the aSound is in the h file
- (void)playOnce:(NSString *)aSound;
- (IBAction) beatButton50
{
[self playOnce:@"racecars"];
}
- (void)playOnce:(NSString *)aSound {
NSString *path = [[NSBundle mainBundle] pathForResource:aSound ofType:@"caf"];
if([theAudio isPlaying])
{
[theAudio stop];
}
}
- (void)playLooped:(NSString *)aSound {
NSString *path = [[NSBundle mainBundle] pathForResource:aSound ofType:@"caf"];
if (!theAudio) {
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL: [NSURL fileURLWithPath: path] error: NULL];
}
[theAudio setDelegate: self];
// loop indefinitely
[theAudio setNumberOfLoops: -1];
[theAudio setVolume: 1.0];
[theAudio play];
}
- (void)stopAudio {
[theAudio stop];
[theAudio setCurrentTime:0];
}