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];
I think your [NSURL URLWithString:filepath] is not right. Can you try with fileURLWithPath method. Hopefully that will solve your issue.