[英]Click on Multiple UIButton how to Play multiple sound at same time duration?
我是Objective-C的新手。 请帮我。 我有一个viewController包含scrollview。 scrollView已启用分页,所以我每页有10页,我有30个按钮。 我的问题是,当单击多个按钮时,我想播放多个声音。
我的代码:-
-(void)buttonClicked:(UIButton *)sender{
if (sender.tag == 1) {
NSString *audioPath = [[NSBundle mainBundle]pathForResource:@"v1" ofType:@"mp3"];
NSURL *url = [NSURL fileURLWithPath:audioPath];
audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil];
audioPlayer.delegate = self;
[audioPlayer play];
}
if (sender.tag == 2) {
NSString *audioPath = [[NSBundle mainBundle]pathForResource:@"v2" ofType:@"mp3"];
NSURL *url = [NSURL fileURLWithPath:audioPath];
audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil];
audioPlayer.delegate = self;
[audioPlayer play];
}
if (sender.tag == 3) {
NSString *audioPath = [[NSBundle mainBundle]pathForResource:@"v3" ofType:@"mp3"];
NSURL *url = [NSURL fileURLWithPath:audioPath];
audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil];
audioPlayer.delegate = self;
[audioPlayer play];
}
问题是当我按下按钮时,只有一种声音被启用。 如何启用多种声音? 请帮助我...在此先感谢
首次导入#import <AudioToolbox/AudioServices.h>
NSString *path = [[NSBundle mainBundle] pathForResource:@"soundeffect" ofType:@"m4a"];
NSURL *pathURL = [NSURL fileURLWithPath : path];
SystemSoundID audioEffect;
AudioServicesCreateSystemSoundID((CFURLRef) pathURL, &audioEffect);
AudioServicesPlaySystemSound(audioEffect);
在每个UIButton
您需要使用需要播放的声音来更改路径。 希望这个帮助:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.