是什么在一个iPhone应用程序播放声音片段最简单的方法? [英] What's the SIMPLEST way to play a sound clip in an iPhone app?

查看:170
本文介绍了是什么在一个iPhone应用程序播放声音片段最简单的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在iPhone OS应用程序来播放声音剪辑。我已经看到了这两个信息的 NSSound 以及 AVFoundation 作为获取声音片段作为手段发挥了iPhone OS设备上,但我仍然没有关于这个问题明确并且可以使用一些帮助。没有必要拼出来,我一步一步的实际code,但如果有人可以给我一个提示,一般的方向(即哪些类我应该专注于)中,我应该开始动我会填空自己。那么,什么是在一个iPhone应用程序播放声音片段最简单的方法?

I want to be able to play a sound clip in an iPhone OS app. I've seen info on both NSSound as well as AVFoundation as being means for getting sound clips played on an iPhone OS device, but I'm still not clear on the subject and could use some help. No need to spell it out for me step-by-step in actual code, but if someone could give me a hint as to the general direction (i.e. which classes I should be focusing on) in which I should start moving I'll fill in the blanks myself. So, what's the SIMPLEST way to play a sound clip in an iPhone app?

推荐答案

苹果有关于这个问题的文章,请参见:<一href=\"http://developer.apple.com/iPhone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AudioandVideoTechnologies/AudioandVideoTechnologies.html#//apple%5Fref/doc/uid/TP40007072-CH19-SW1\">this链接

Apple has an article on this subject, see: this link

AVAudioPlayer是玩任意长度的声音,循环与否最简单的方法,但它需要iPhone OS 2.2或更高版本。一个简单的例子:

AVAudioPlayer is the simplest way to play sounds of any length, looping or not, however it requires iPhone OS 2.2 or higher. A simple example:

NSString *soundFilePath =
                [[NSBundle mainBundle] pathForResource: @"sound"
                                                ofType: @"wav"];

NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];

AVAudioPlayer *newPlayer =
                [[AVAudioPlayer alloc] initWithContentsOfURL: fileURL
                                                       error: nil];
[fileURL release];

[newPlayer play];

[newPlayer release];

这将播放几乎所有的文件格式(AIFF,WAV,MP3,AAC)请记住,你只能一次播放的MP3 / AAC格式的文件。

It will play virtually any file format (aiff,wav,mp3,aac) Keep in mind that you can only play one mp3/aac file at a time.

这篇关于是什么在一个iPhone应用程序播放声音片段最简单的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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