Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass custom mp3 file path in VideoEditorModule.applyAudioTrack() #38

Open
MiteshKalal7 opened this issue Dec 1, 2023 · 0 comments

Comments

@MiteshKalal7
Copy link

Need to modify applyAudioTrack function in VideoEditorModule.swift to working dynamic mp3 file path

// Applies audio track from custom audio browser
  @objc func applyAudioTrack(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
    self.currentResolve = resolve
    self.currentReject = reject
    
    // Specify audio track URL. Video Editor SDK can apply tracks stored on the device.
    // In this sample we use audio file stored in the project.
    let audioURL = Bundle.main.url(forResource: "sample_audio", withExtension: "mp3")
    
    if (audioURL == nil) {
      let errMessage = "Failed to apply audio track. Unknow file"
      print(errMessage)
      self.currentReject!("", errMessage, nil)
      return
    }
    
    // Specify custom track name and additional data
    let trackName = "Track Name"
    let additionTitle = "Awesome artist"
    
    DispatchQueue.main.async {
      self.customAudioTrackUUID = UUID()
      let audioBrowserModule = self.getAudioBrowserModule()
      
      // Apply audio in Video Editor SDK
      audioBrowserModule.trackSelectionDelegate?.trackSelectionViewController(
        viewController: audioBrowserModule,
        didSelectFile: audioURL!,
        isEditable: true,
        title: trackName,
        additionalTitle: additionTitle,
        uuid: self.customAudioTrackUUID!
      )
      
      print("Audio track is applied")
      
      self.currentResolve!(nil)
    }
  }

so i can pass directly mp3 path from JS, something like this

return await VideoEditorModule.applyAudioTrack(
    "file:///Users/miteshkalal/Library/Developer/CoreSimulator/Devices/CAB59D05-4642-41F1-B9C1-C22D5892E263/data/Containers/Data/Application/5E7C48C9-83E9-42DB-9989-7669199AB6DC/Library/Caches/music.mp3"
  );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant