How to play multiple audio files using AVAudioPlayer

荒凉一梦 提交于 2019-12-11 06:43:31

问题


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.

Please help me out


回答1:


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



来源:https://stackoverflow.com/questions/3744826/how-to-play-multiple-audio-files-using-avaudioplayer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!