第一次使用音頻。可能是我缺少的東西,請指導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