I need to add a background sound in my application. Where I can add it and how?
Asked
Active
Viewed 1,966 times
1
-
http://stackoverflow.com/questions/1973902/play-mp3-files-with-iphone-sdk – tipycalFlow Apr 15 '12 at 10:18
-
https://www.google.co.in/search?sourceid=chrome&ie=UTF-8&q=ios+play+audio+file – tipycalFlow Apr 15 '12 at 10:18
1 Answers
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
-
Thank you for help. Just for mine understand I put this code, for example in my Appdelegate.m near applicationDidFinishLaunching? I not need a button. – user1322754 Apr 15 '12 at 10:42
-
Yes, you can put it in applicationDidFinishLaunching or maybe applicationDidBecomeActive. – EricS Apr 15 '12 at 14:32
-
-