1

I need to add a background sound in my application. Where I can add it and how?

Brian Webster
  • 28,703
  • 48
  • 145
  • 221

1 Answers1

4

Here you go:

Add the sound to your resource folder in xcode and then add this code to your code wherever you want the sound to play. (In a button click method for example)

NSString *path = [[NSBundle mainBundle]pathForResource:@"NameOfSoundfile" ofType:@"mp3"];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[audioPlayer play];
AlexanderN
  • 2,460
  • 1
  • 25
  • 42