Dhaval Tannarana Dhaval Tannarana - 1 year ago 640
iOS Question

How to convert AVAsset to NSData or save it to file manager

I am trying to do that using

to record Audio file and then after first i store it on
and after that by convert it to nsdata i Call API to store it.

I am successful to Create
recording file and play it using third party Class that is

Now problem is that i don't know how to Use
file for save it in file manager and then after call API to sent it by converting it to

Is any way to convert

Please Help...

Answer Source

You can do the following:

  1. Use AVAssetExportSession to export your AVAsset object to a file path URL.
  2. Convert it to NSData using its dataWithContentsOfURL method.

    NSURL *fileURL = nil;
    __block NSData *assetData = nil;
    // asset is you AVAsset object
    AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetHighestQuality];
    exportSession.outputURL = fileURL;
    // e.g .mov type 
    exportSession.outputFileType = AVFileTypeQuickTimeMovie; 
    [exportSession exportAsynchronouslyWithCompletionHandler:^{
        assetData = [NSData dataWithContentsOfURL:fileURL];
        NSLog(@"AVAsset saved to NSData.");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download