【发布时间】:2011-03-23 23:26:44
【问题描述】:
我在一个视图中有 6 个声音。
但是我想要它,以便我可以一次播放多个,所以你点击声音 1(声音 1 正在播放)然后声音 2 播放。当声音 1 仍在播放时。
但此刻我按下声音 1(声音 1 播放),按声音 2(声音 2 播放,但声音 1 停止)
这是音频部分的代码。
- (IBAction)oneSound:(id)sender; {
NSString *path = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"wav"];
if (theAudio) [theAudio release];
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play];
volumeTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(updateVolume) userInfo:nil repeats:YES];
}
- (IBAction)twoSound:(id)sender; {
NSString *path = [[NSBundle mainBundle] pathForResource:@"2" ofType:@"wav"];
if (theAudio) [theAudio release];
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play];
volumeTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(updateVolume) userInfo:nil repeats:YES];
}
【问题讨论】:
标签: iphone objective-c avaudioplayer