使用 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];