AVAsset from app sandbox

790 views Asked by At

I'm working with AVAsset in my app and met next problem. When I'm writing something like this:

AVAsset *audioAsset = [AVAsset assetWithURL:[NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/Hello.mp3", [[NSBundle mainBundle] resourcePath]]]];

its work fine. But when I trying get fresh recorded file from my tmp directory from in app's sandbox like that:

AVAsset *audioAsset2 = [AVAsset assetWithURL:[NSURL URLWithString:[NSTemporaryDirectory() stringByAppendingPathComponent:[@"speechRecord" stringByAppendingPathExtension:@"m4a"]]]];

it doesn't work too. Even if I trying add video file to asset from sandbox - result is the same. I even tried work with AVURLAsset, but asset always empty too. I need it to mix two audio files between themselves and then merge it with recorded video. If I can do that without AVAssets and there is another way, I will appreciate if You tell me. Or may there is some another function for that?

1

There are 1 answers

0
nico On

You create the second URL for audioAsset2 with the URLWithString selector. Your first asset loaded correctly, because you used the fileURLWithPath selector.

If you want to load a file at a given URL always create the NSURL object with the fileURLWithPath selector.

So simply try:

AVAsset *audioAsset2 = [AVAsset assetWithURL:[NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:[@"speechRecord" stringByAppendingPathExtension:@"m4a"]]]];