Skip to main content

Launching from SwiftUI

Configuration

Custom behavior of the Video Editor SDK in your app is implemented using a number of configuration classes. The VideoEditorConfig is the main entity used for the Video Editor configuration:

func createConfiguration() -> VideoEditorConfig {
var config = VideoEditorConfig()
...
return config
}

Check out the demo project for an example of creating VideoEditorConfig.

The following configuration starts the Video Editor from the camera screen:

func createLaunchConfiguration() -> VideoEditorLaunchConfig {
let launchConfig = VideoEditorLaunchConfig(
entryPoint: .camera,
hostController: UIViewController(),
musicTrack: nil, // Paste a music track as a track preset at the camera screen to record video with music.
animated: true
)
return launchConfig
}

The Video Editor supports multiple launch methods described in this guide.

The Video Editor can export multiple media files to meet your requirements.
Create an instance of ExportConfiguration and provide Array<ExportVideoConfiguration> where every ExportVideoConfiguration is a media file i.e. a video or audio:

func createExportConfiguration() -> ExportConfiguration {
let url = FileManager
.default
.temporaryDirectory
.appendingPathComponent("video.mov")
if FileManager.default.fileExists(atPath: url.path) {
try? FileManager.default.removeItem(at: url)
}

let exportVideoConfiguration: ExportVideoConfiguration =
ExportVideoConfiguration(
fileURL: url,
quality: .auto,
useHEVCCodecIfPossible: true,
watermarkConfiguration: nil
)

let exportConfiguration = ExportConfiguration(
videoConfigurations: [exportVideoConfiguration],
isCoverEnabled: true,
gifSettings: nil
)

return exportConfiguration
}

Please, check out the export implementation in the sample. Learn the Export integration guide to know more about exporting media content features.

Launch

Use BanubaVideoEditorSwiftUIView with the license token to present the Video Editor SDK:

@State private var isPresentingVideoEditor = false

.fullScreenCover(isPresented: $isPresentingVideoEditor) {
BanubaVideoEditorSwiftUIView(
token: "",
launchConfig: createLaunchConfiguration(),
configuration: createConfiguration(),
exportConfiguration: createExportConfiguration()
)
.onDidCancel {
// The user tapped on the cancel button. Dismissing the video editor.
isPresentingVideoEditor = false
}
.onDidSave { videoURLs in
// The video export is succeed. Dismissing the video editor.
isPresentingVideoEditor = false
}
.onUpdateProgress { progress in
// Current export progress.
}
.onDidFail { error in
// Dismissing the video editor.
isPresentingVideoEditor = false
switch error {
case .exportError(let description):
// There was an error exporting the video.
case .initError:
// There was an error with init of Video Editor SDK.
case .licenseError:
// There was an error with license.
@unknown default:
break
}
}
.ignoresSafeArea()
}