第一次使用音频。可能是我缺少的东西,请指导AVAudioPlayer在播放时崩溃
我已添加AVFoundation框架。添加了#import
并将其添加到viewDidLoad中。
NSString* docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString* audioPath = [docPath stringByAppendingPathComponent:@"001.mp3"];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:audioPath];
if (!fileExists) {
NSLog(@"Audio File not exist!");
}else{
NSError *error;
NSURL *url = [[NSURL alloc] initFileURLWithPath:audioPath];
NSData *audioData = [NSData dataWithContentsOfURL:url];
self.audioPlayer = [AVAudioPlayer alloc];
// It crashes at this line
self.audioPlayer = [self.audioPlayer initWithData:audioData error:&error];
NSLog(@"%@",self.audioPlayer);
}
什么消息崩溃? – zoul
只在打印输出(lldb) – Mani