如何使用AVAudioPlayer播放多个音频文件

如何使用AVAudioPlayer播放多个音频文件

本文介绍了如何使用AVAudioPlayer播放多个音频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,当我单击图像时,我将在行和列中显示多个图像,我将使用

In my application, I am displaying multiple images in rows and columns when i click on a image i will play corresponding sound using

someName = [someName stringByAppendingFormat:@".mp3"];
[audioPlayer stop];

NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%s", [[NSBundle mainBundle] resourcePath],[someName UTF8String]]];

NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.delegate = self;

当我单击一张图像时,我会得到特定的图像声音.当我单击另一张图像时,先前的声音将停止并播放与该图像对应的新声音.

When i am clicking on the one image i will get particular image sound. When i click on the another image the previous sound will be stopped and new sound corresponding the image will be played.

我的要求是,当我单击第一幅图像时,声音必须到来,而当我单击第二幅图像时,第一声音不能停止并且都必须播放,而当我单击第三幅时,必须播放三种声音.

My requirement is when i click on the first image the sound must come and when i click on the second image the first sound must not stop and both must play and when i click on the third one the three sounds must play.

请帮帮我

推荐答案

Apple建议使用IMA4编码的* .caf文件一次播放多个声音.

Apple recommends using an IMA4 encoded *.caf file for playing multiple sounds at once.

这篇关于如何使用AVAudioPlayer播放多个音频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 19:51