使用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];
我认为您的[NSURL URLWithString:filepath]不正确。您可以尝试使用fileURLWithPath方法吗?希望能解决您的问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句