2

I have an audio file that is 2 seconds long. Im trying to play that many times before it is done playing. But when I try it with AVAudioPlayer by creating a new instance of it, it sounds like it stops the audio that was played before and plays the new one instead of playing them at the same time. Should I use another way to play sounds or is this not achievable?

Code:

NSURL *url = [[NSBundle mainBundle] URLForResource:@"PistolShootSound" withExtension:@"mp3"];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
[audioPlayer play];

audioPlayer is declared in the header file.

Arbitur
  • 38,684
  • 22
  • 91
  • 128

1 Answers1

1

Have you used AVAudioPlayer's property numberOfLoops to play audio file repeatedly?

UPDATE: I didn't understand your goal before. If you want to play short files many times you could use AudioServices. Here is a good example of how to use it.

Community
  • 1
  • 1
Arek Holko
  • 8,966
  • 4
  • 28
  • 46
  • Thats not what I want to do, this will loop the sound file I only want to play it once, its going to be the sound for a gun and guns can shoot very fast. If I put a loop for the sound it will play the sound when its not firing. – Arbitur Oct 06 '13 at 12:28
  • Nice it works like I want it now! Thank you sooooo much I want to upvote this 1 mil times :D – Arbitur Oct 06 '13 at 12:48