本文介绍了在iPhone中播放声音片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iPhone开发的新手.我想编写一个具有3个按钮的应用程序.触摸每个都会触发声音.

I'm new to iphone development. i want to write an app that has 3 buttons. touching each will trigger a sound.

有人可以给我一些提示并引导我走正确的路吗?

Can someone give me some hints and guide me to the right path?

推荐答案

以下是在按钮单击事件中播放.wav文件的示例代码:

Here is the sample code to play .wav files on button click event:

-(void) playWavFile{
       SystemSoundID   soundFileObject;
       CFURLRef soundFileURLRef = CFBundleCopyResourceURL (CFBundleGetMainBundle (),CFSTR ("1"),CFSTR ("wav"),NULL );
       AudioServicesCreateSystemSoundID (soundFileURLRef,&soundFileObject );
       AudioServicesPlaySystemSound (soundFileObject);
}

-(IBAction) button1Pressed:(id)sender
{
       [self playWavFile];
}


谢谢,
吉姆.


Thanks,
Jim.

这篇关于在iPhone中播放声音片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 15:01