下面我们已经粘贴了确切的代码
NSString *playSoundOnAlert = @"Sound.wav";
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@",[[NSBundle mainBundle] resourcePath],playSoundOnAlert]];
NSError *error;
aVAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
aVAudioPlayer.numberOfLoops = 0;
[aVAudioPlayer play];
答案 0 :(得分:1)
检查代码:
NSString *playSoundOnAlert = @"Sound";
AVAudioPlayer *audioPlayer;
NSString *audioPath = [[NSBundle mainBundle] pathForResource: playSoundOnAlert ofType:@".wav"];
NSURL *audioURL = [NSURL fileURLWithPath:audioPath];
NSError *audioError = [[NSError alloc] init];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioURL error:&audioError];
if (!audioError) {
[audioPlayer play];
NSLog(@"playing!");
}
else {
NSLog(@"Error!");
}