NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString * documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/audio.mp3",documentsDirectory];
NSURL *audioPathURL = [NSURL fileURLWithPath:filePath];
NSFileManager *filemanager = [[NSFileManager alloc]init];
if ([filemanager fileExistsAtPath:filePath])
{
AVAudioFile *audioFile = [[AVAudioFile alloc] initForReading:audioPathURL error:&err];
}
这无法读取音频文件,它返回 audioFile nil。当我从 NSBundle 传递 url 时,对于相同的代码
NSString *path = [[NSBundle mainBundle] pathForResource:@"Audio" ofType:@"mp3"];
NSURL *pathURL = [NSURL fileURLWithPath : path];
它工作正常,任何建议。谢谢