Looking for
or
?
We've rebranded!
API Docs

Audio Composition

The VideoEditor SDK supports adding predefined audio libraries from which an audio clip can be overlayed on top of the video’s soundtrack. Inside the audio tool, the audio clip can be trimmed and balanced with the original soundtrack of the video. The corresponding tool is implemented in the AudioToolController class and can be customized using the AudioToolControllerOptions.

For details on how to modify the options for the tool, take a look at the configuration section.

Adding audio clips

Audio clips are inserted into the SDK using the static property AudioClipCategory.all, which is an array of AudioClipCategory objects. An AudioClipCategory object holds the metadata of an audio clip category, such as its preview image and the title and has an array of AudioClip objects, which again hold the metadata for an AudioClip, such as its audioURL, thumbnailURL and the duration. The AudioClip class is not optimized to handle remote resources which therefore should be downloaded in advance and then passed as a local resource.

let audioClips = [
  Bundle.main.url(forResource: "rain", withExtension: "mp3"),
  Bundle.main.url(forResource: "thunder", withExtension: "mp3"),
  Bundle.main.url(forResource: "explosion", withExtension: "mp3"),
  Bundle.main.url(forResource: "clapping", withExtension: "mp3"),
  Bundle.main.url(forResource: "laughing", withExtension: "mp3")
].compactMap { $0.map { AudioClip(identifier: $0.lastPathComponent, audioURL: $0) } }

if let previewURL = Bundle.main.url(forResource: "effects", withExtension: "png") {
  let category = AudioClipCategory(title: "Effects", imageURL: previewURL, audioClips: audioClips)
  AudioClipCategory.all = [category]
}
NSArray<NSURL *> *audioClipURLs = @[
  [[NSBundle mainBundle] URLForResource:@"rain" withExtension:@"mp3"],
  [[NSBundle mainBundle] URLForResource:@"thunder" withExtension:@"mp3"],
  [[NSBundle mainBundle] URLForResource:@"explosion" withExtension:@"mp3"],
  [[NSBundle mainBundle] URLForResource:@"clapping" withExtension:@"mp3"],
  [[NSBundle mainBundle] URLForResource:@"laughing" withExtension:@"mp3"]
];

NSMutableArray<PESDKAudioClip *> *audioClips = [[NSMutableArray alloc] init];
for (NSURL *audioClipURL in audioClipURLs) {
  [audioClips addObject:[[PESDKAudioClip alloc] initWithIdentifier:audioClipURL.lastPathComponent audioURL:audioClipURL]];
}
PESDKAudioClipCategory *category = [[PESDKAudioClipCategory alloc] initWithTitle:@"Effects" imageURL:[[NSBundle mainBundle] URLForResource:@"effects" withExtension:@"png"] audioClips:audioClips];
PESDKAudioClipCategory.all = @[category];