1

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

1 回答 1

3

我认为您的 [NSURL URLWithString:filepath] 不正确。您可以尝试使用 fileURLWithPath 方法吗?希望这能解决您的问题。

于 2015-01-20T13:20:00.083 回答