Skip to main content

Present Video Editor using UIKit

The VideoEditViewController class is responsible for presenting and rendering a video. It can be presented modally as in this example in which case it will display a toolbar at the bottom or it can be pushed onto a UINavigationController in which case it will use the navigation controller’s navigation bar. It also handles the presentation of PhotoEditToolController subclasses.

Create the video edit controller#

In this example, we present a video from the bundle passing the URL to the Video constructor. We then initialize a VideoEditViewController instance passing the video as videoAsset.

Implement delegate method#

We set the delegate of the VideoEditViewController object to self. That means that the presenting view controller must implement the VideoEditViewControllerDelegate protocol. The methods of the VideoEditViewControllerDelegate protocol are designed to inform the delegate about the result of the editing process (for example cancellation).

When a user confirms the edits to a video the videoEditViewControllerDidFinish method is called and the URL to the finished video is passed as part of the result type argument.

Next Steps#

import UIKit
import VideoEditorSDK
class ShowVideoEditorUIKitSwift: Example, VideoEditViewControllerDelegate {
override func invokeExample() {
// Create a `Video` from a URL to a video in the app bundle.
let video = Video(url: Bundle.main.url(forResource: "Skater", withExtension: "mp4")!)
// Create and present the video editor. Make this class the delegate of it to handle export and cancelation.
let videoEditViewController = VideoEditViewController(videoAsset: video)
videoEditViewController.delegate = self
videoEditViewController.modalPresentationStyle = .fullScreen
presentingViewController?.present(videoEditViewController, animated: true, completion: nil)
// MARK: - VideoEditViewControllerDelegate
func videoEditViewControllerShouldStart(_ videoEditViewController: VideoEditViewController, task: VideoEditorTask) -> Bool {
// Implementing this method is optional. You can perform additional validation and interrupt the process by returning `false`.
func videoEditViewControllerDidFinish(_ videoEditViewController: VideoEditViewController, result: VideoEditorResult) {
// The user exported a new video successfully and the newly generated video is located at `result.output.url`. Dismissing the editor.
presentingViewController?.dismiss(animated: true, completion: nil)
func videoEditViewControllerDidFail(_ videoEditViewController: VideoEditViewController, error: VideoEditorError) {
// There was an error generating the video.
// Dismissing the editor.
presentingViewController?.dismiss(animated: true, completion: nil)
func videoEditViewControllerDidCancel(_ videoEditViewController: VideoEditViewController) {
// The user tapped on the cancel button within the editor. Dismissing the editor.
presentingViewController?.dismiss(animated: true, completion: nil)