当我按下按钮以及如何修复重叠声音时,声音没有播放

时间:2011-11-12 01:08:17

标签: iphone ios4 audio avaudioplayer

  

可能重复:
  Sound stop playing
  iPhone - Sound overlapping with multiple button presses

代码给我一个错误“Unused variable'path'”当我按下一个按钮没有声音播放我如何解决这个问题aSound是在h文件中

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

0 个答案:

没有答案