播放声音在iPhone SDK?

编程入门 行业动态 更新时间:2024-10-24 17:18:56
本文介绍了播放声音在iPhone SDK?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有人有一个使用AudioToolBox框架,可以用来播放一个简短的声音片段?如果你跟我和社区的其余部分共享它,我将不胜感激。其他地方我已经看过似乎并不符合他们的code昭然若揭。

Does anyone have a snippet that uses the AudioToolBox framework that can be used to play a short sound? I would be grateful if you shared it with me and the rest of the community. Everywhere else I have looked doesn't seem to be too clear with their code.

谢谢!

推荐答案

下面是一个使用AVAudioPlayer一个简单的例子:

Here is an easy example using the AVAudioPlayer:

-(void)PlayClick { NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"click" ofType:@"caf"]]; AVAudioPlayer *click = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil]; [click play]; [click release]; }

这假定一个名为click.caf的主束可用文件。由于我玩这个声音很多,其实我把它周围发挥它,而不是稍后释放它的。

This assumes a file called "click.caf" available in the main bundle. As I play this sound a lot, I actually keep it around to play it later instead of releasing it.

更多推荐

播放声音在iPhone SDK?

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

发布评论

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

>www.elefans.com

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