使用AVAssetReader读取文件时,我收到Exc_bad_Access异常。 文件位于文档目录中,格式为m4a。这是我正在使用的代码。无法弄清楚哪里弄错了:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filepath = [documentsDirectory stringByAppendingPathComponent:@"My_Recording2.m4a"];
NSURL *newURL=[NSURL URLWithString:filepath];
if ([[NSFileManager defaultManager] fileExistsAtPath:newURL.absoluteString])
{
NSLog(@"File exists");
}
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:newURL options:nil];
NSError *assetError;
if(asset)
NSLog(@"all ok");
self.assetReader = [AVAssetReader assetReaderWithAsset:asset error:&assetError];
我在最后一行得到例外,即
self.assetReader = [AVAssetReader assetReaderWithAsset:asset error:&assetError];
答案 0 :(得分:3)
我认为您的[NSURL URLWithString:filepath]不正确。 你可以尝试使用fileURLWithPath方法。希望这能解决您的问题。