0
我有兩個不同的wav文件,我必須通過調用不同的方法來播放。我可以播放一個wav文件,但無法播放該文件。我的代碼是如何在iPhone SDK中播放兩種不同的聲音?
在.H
AVAudioPlayer *player1, *player2;
在.M
-(void)correctSound {
NSString *sound = [[NSString alloc] initWithFormat:@"claps2"];
NSLog(@"sound claps %@", sound);
NSURL *url = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:sound ofType:@"wav"]];
NSLog(@"claps url %@", url);
player1 = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
player1.delegate = self;
player1.volume = 1.0;
[player1 prepareToPlay];
[player1 play];
[sound release];
[url release];
}
-(void)wrongSound {
NSString *sound1 = [[NSString alloc] initWithFormat:@"boo"];
NSLog(@"sound boo %@", sound1);
NSURL *url1 = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:sound1 ofType:@"wav"]];
NSLog(@"boo url %@", url1);
NSError *error;
player2 = [[AVAudioPlayer alloc] initWithContentsOfURL:url1 error:&error];
NSLog(@"localizedDescription = %@",[error localizedDescription]);
player2.delegate = self;
player2.volume = 1.0;
[player2 prepareToPlay];
[player2 play];
[sound1 release];
[url1 release];
}
更新 Play multiple audio files using AVAudioPlayer 我看到這個鏈接,但它不是對我很有幫助。如何才能做到這一點?代碼示例將不勝感激。 在控制檯中出現以下錯誤說明。
localizedDescription = The operation couldn’t be completed. (OSStatus error 1685348671.)
請幫我解決這個問題。在此先感謝