播放声音在iPhone SDK? [英] Playing sounds in iPhone SDK?

查看:141
本文介绍了播放声音在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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆