【发布时间】:2011-09-22 15:40:19
【问题描述】:
我有两个不同的 wav 文件,我必须通过调用不同的方法来播放它们。我可以播放一个 wav 文件,但无法播放那个。我的代码是
在.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.)
请帮我解决这个问题。提前致谢
【问题讨论】:
标签: avaudioplayer iphone-sdk-4.3