ios - Trim more than one middle range from audio track using AVFoundation -


i want cut multiple ranges audio track using removetimerange method in avfoundation, implemented following method

func removeundotimes(undostack:[(start:double, end:double)]){             let url = url(fileurlwithpath: audiorecorderservice.audiotemppath)          let  asset = avurlasset(url: url, options: nil)          let assettrack = asset.tracks(withmediatype: avmediatypeaudio)[0]          let composition = avmutablecomposition()          let compositionaudiotrack:avmutablecompositiontrack = composition.addmutabletrack(withmediatype: avmediatypeaudio, preferredtrackid:kcmpersistenttrackid_invalid)            {              try compositionaudiotrack.inserttimerange(assettrack.timerange, of: assettrack, at: kcmtimezero)            } catch let error {         }          let timescale = assettrack.naturaltimescale           action in undostack {              let start = cmtimemakewithseconds(action.start / 1000, timescale)             cmtimeshow(start)              let end =  cmtimemakewithseconds(action.end / 1000, timescale)             cmtimeshow(end)              let slicerange = cmtimerangemake(start, end)             cmtimerangeshow(slicerange)               compositionaudiotrack.removetimerange(slicerange)            }           let exporter = avassetexportsession(asset: composition, presetname: avassetexportpresetapplem4a)          exporter?.outputfiletype = avfiletypeapplem4a          if fcfilemanager.existsitem(atpath: audiorecorderservice.editedaudiotemppath) {             fcfilemanager.removeitem(atpath: audiorecorderservice.editedaudiotemppath)         }           exporter?.outputurl =  url(fileurlwithpath:audiorecorderservice.editedaudiotemppath)          exporter?.timerange = compositionaudiotrack.timerange           exporter?.exportasynchronously() {              switch exporter!.status {             case .unknown,.waiting, .exporting:                 print("exported waiting")             case .completed:                 print("exported complete")             case  .failed:                 print("exported failed \(exporter?.error?.localizeddescription ?? "")")             case .cancelled:                 print("exported cancelled \(exporter!.error?.localizeddescription)")             }         }      } 

result of execution if input [(4,5),(3.5,4),(2,3)] range second 2 end of track removed.

i need make above method run properly.

thanks in advance.


Comments

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

javascript - Confirm a form & display message if form is valid with JQuery -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -