1

I am getting Exc_bad_Access exception while reading a file with AVAssetReader . The File is located in document directory and is in m4a format. Here is the code i am using. Not able to figure out where m getting it wrong:

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

I am getting the exception at last line i.e.

self.assetReader = [AVAssetReader assetReaderWithAsset:asset error:&assetError];
Tornado
  • 1,069
  • 12
  • 28

1 Answers1

3

I think your [NSURL URLWithString:filepath] is not right. Can you try with fileURLWithPath method. Hopefully that will solve your issue.

Nikhil.T
  • 241
  • 2
  • 13
  • after this i am using AVURLAsset* audioAsset = [[AVURLAsset alloc]initWithURL:newURL options:nil]; NSError *assetError; if(audioAsset) NSLog(@"all ok"); NSLog(@" array is %@",audioAsset.tracks); to get track but track array is empty if i log can you tell me why ? – Tornado Jan 22 '15 at 10:42
  • If url is correct (check first its correct) then as documentation says sometimes you have to make sure if tracks loaded. Use loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:@"tracks"] completionHandler: ^{ //for that. – Nikhil.T Jan 22 '15 at 12:55