1

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

Brian Webster
  • 30,033
  • 48
  • 152
  • 225

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,610
  • 1
  • 26
  • 42