sound not playing when i press the button and how to fix overlapping sounds

Posted by alfredjunco on Stack Overflow See other posts from Stack Overflow or by alfredjunco
Published on 2011-11-12T01:08:17Z Indexed on 2011/11/12 1:51 UTC
Read the original article Hit count: 109

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];
   }

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk-4.0