如何将背景声音添加到iPhone应用程序

如何将背景声音添加到iPhone应用程序

问题描述:

我需要在我的应用程序中添加背景声音。我可以在哪里添加它以及如何添加?如何将背景声音添加到iPhone应用程序

+0

http://*.com/questions/1973902/play-mp3-files-with-iphone-sdk – tipycalFlow 2012-04-15 10:18:23

+0

https://www.google.co.in/search?sourceid = chrome&ie = UTF-8&q = ios + play + audio +文件 – tipycalFlow 2012-04-15 10:18:40

在这里你去:

声音添加到您的资源文件夹在Xcode,然后不管你想要的声音播放此代码添加到您的代码。 (在一个按钮点击例如方法)

NSString *path = [[NSBundle mainBundle]pathForResource:@"NameOfSoundfile" ofType:@"mp3"]; 
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL]; 
[audioPlayer play]; 
+0

谢谢你的帮助。为了我的理解,我把这段代码放在applicationDidFinishLaunching附近的Appdelegate.m中?我不需要一个按钮。 – user1322754 2012-04-15 10:42:21

+0

是的,你可以把它放在applicationDidFinishLaunching或者applicationDidBecomeActive中。 – EricS 2012-04-15 14:32:55

+0

@EricS说什么。 – 2012-04-15 16:17:24