如何在iPhone应用程序中播放声音(How to play sounds in iPhone app)

编程入门 行业动态 更新时间:2024-10-27 23:29:52
如何在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.

更多推荐

本文发布于:2023-07-31 14:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1345278.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   声音   如何在   iPhone   app

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!