我正在制作一个应用程序,我有10个声音剪辑(mp3,短片)和10个图像,图像是水果和每一个水果图像,我想要那个特定的水果声音剪辑播放。在Play Button上单击。
看我的代码..。它只播放一个剪辑
.h文件
@interface FruitsViewController : UIViewController
{
SystemSoundID fruitSound;
}.m文件
- (IBAction)btnPlayClicked:(id)sender {
NSURL * soundURL = [[NSBundle mainBundle]
URLForResource:@"fruits_s_01" withExtension:@"mp3"];
AudioServicesCreateSystemSoundID((CFURLRef)CFBridgingRetain(soundURL), &fruitSound);
AudioServicesPlaySystemSound(fruitSound);
}发布于 2015-11-25 07:04:55
用2个数组的音乐文件映射水果图像
for example if there is an image as "1" then load the music files "Music1"以这种方式,您可以从数组中来回遍历,并通过在AudioPlayer实例中加载音乐文件来播放音乐文件。
发布于 2015-11-25 06:23:19
可以将声音文件的名称存储在数组中,并在有fruitSound变量的类中将该数组设置为属性或私有。每次单击btnPlayClicked时,都会增加数组并从数组中获取文件名,并将其传递给urlforresource。希望能帮上忙。:)
https://stackoverflow.com/questions/33909107
复制相似问题