ios - How can I trim an audio recorded with EZAudioRecorder? -


i want trim audio recorded ezaudiorecorder.

i writing code trim audio. working fine audio recorded avaudiorecorder triggers error block ezaudiorecorder, error couldn't open file.

-(bool)trimaudiofile{    float audiostarttime=1.0;    float audioendtime=2.0;//define end time of audio    nsdateformatter *dateformatter = [[nsdateformatter alloc] init];    [dateformatter setdateformat:@"yyyy-mm-dd_hh-mm-ss"];    nsarray *paths = nssearchpathfordirectoriesindomains(nslibrarydirectory, nsuserdomainmask, yes);    nsstring *librarycachesdirectory = [paths objectatindex:0];    librarycachesdirectory = [librarycachesdirectory stringbyappendingpathcomponent:@"caches"];    nsstring *outputfilepath = [librarycachesdirectory stringbyappendingformat:@"/output_%@.m4a", [dateformatter stringfromdate:[nsdate date]]];    nsurl *audiofileoutput = [nsurl fileurlwithpath:outputfilepath];    nsurl *audiofileinput=[self testfilepathurl];//<path of orignal audio file>     if (!audiofileinput || !audiofileoutput)    {        return no;    }    [[nsfilemanager defaultmanager] removeitematurl:audiofileoutput error:null];   avasset *asset = [avasset assetwithurl:audiofileinput];    avassetexportsession *exportsession = [avassetexportsession exportsessionwithasset:asset                                                                     presetname:avassetexportpresetapplem4a];  if (exportsession == nil)  {      return no;  }  cmtime starttime = cmtimemake((int)(floor(audiostarttime * 100)), 100);  cmtime stoptime = cmtimemake((int)(ceil(audioendtime * 100)), 100);  cmtimerange exporttimerange = cmtimerangefromtimetotime(starttime, stoptime);   exportsession.outputurl = audiofileoutput;  exportsession.timerange = exporttimerange;  exportsession.outputfiletype = avfiletypeapplem4a;  [exportsession exportasynchronouslywithcompletionhandler:^ {    if (avassetexportsessionstatuscompleted == exportsession.status)    {      nslog(@"export ok");    }    else if (avassetexportsessionstatusfailed == exportsession.status)    {      nslog(@"export failed: %@", [[exportsession error] localizeddescription]);    }  }];  return yes; } 

note:- audio file exists in document directory , ezaudioplayer able play file.

can tell me doing wrong ? on appreciated.

thanks in advance.

1.check file formate in both cases when trim audio recorded avaudiorecorder , audio ezaudiorecorder.

2.you trying export file before record audio successfully,you have wait until audio not recorded.


Comments