我正在使用AVFoundation播放wav文件,但是我无法使它正常播放。而且也没有出现任何错误或警告。
XCode版本为4.2,设备系统为iOS 5。
- (IBAction) playSelectedAlarm:(id)sender {
UIButton *button = (UIButton *)sender;
int bTag = button.tag;
NSString *fileName = [NSString stringWithFormat:@"%d23333", bTag];
NSLog(@"%@", fileName);
NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"wav"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: path];
AVAudioPlayer *theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:NULL];
theAudio.volume = 1.0;
theAudio.delegate = self;
[theAudio prepareToPlay];
[theAudio play];
}
AVAudioPlayer *theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:&audioError]; if(audioError != nil) { NSLog(@"发生音频错误:\"%@\"", audioError); } else { [theAudio prepareToPlay]; [theAudio play]; }`
- Quaso