【问题标题】:Getting Exc_Bad_access in AVAssetReader在 AVAssetReader 中获取 Exc_Bad_access
【发布时间】:2015-01-20 12:20:35
【问题描述】:

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

【问题讨论】:

  • 使用 AVAsset assetWithURL: 只是为了尝试 AVURLAsset 可能是用于 web 内容。您的assetReader 属性是否设置为strong?
  • 是的assetReader 属性很强大。我尝试使用assetWithURL 仍然是相同的结果。

标签: ios objective-c iphone avasset avassetreader


【解决方案1】:

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

【讨论】:

  • 在此之后我使用 AVURLAsset* audioAsset = [[AVURLAsset alloc]initWithURL:newURL options:nil]; NSError *assetError; if(audioAsset) NSLog(@"一切正常"); NSLog(@" 数组是 %@",audioAsset.tracks);获取跟踪但如果我记录跟踪数组为空你能告诉我为什么吗?
  • 如果 url 正确(首先检查它是否正确),那么正如文档所说,有时您必须确保是否加载了曲目。使用 loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:@"tracks"] completionHandler: ^{ //for that.
猜你喜欢
  • 2011-03-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多