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

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -