如何在iPhone应用程序中播放声音(How to play sounds in iPhone app)
我是这个非常令人困惑的Objective-C游戏的初学者。
每次按下某个按钮,我都想播放非常短的音效。
我怎样才能做到这一点?
我可以使用mp3文件吗? 或者我必须转换为wav?
I am a beginner in this very confusing Objective-C game.
I would like to play a very short sound effect every time a certain button is pushed.
How can I do this?
Can I use an mp3 file? Or will I have to convert to wav?
最满意答案
您可以使用系统声音服务播放短音:
CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef soundFileURLRef = CFBundleCopyResourceURL(mainBundle, CFSTR("filename"), CFSTR("aiff"), NULL); SystemSoundID soundId; AudioServicesCreateSystemSoundID(soundFileURLRef, &soundId); AudioServicesPlaySystemSound(soundId); CFRelease(soundFileURLRef)支持.caf,.aiff和.wav格式。
You can use System Sound Services to play short sounds:
CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef soundFileURLRef = CFBundleCopyResourceURL(mainBundle, CFSTR("filename"), CFSTR("aiff"), NULL); SystemSoundID soundId; AudioServicesCreateSystemSoundID(soundFileURLRef, &soundId); AudioServicesPlaySystemSound(soundId); CFRelease(soundFileURLRef).caf, .aiff and .wav formats are supported.
更多推荐
发布评论