From 284dfcec151ee357f8da6cda532c89ea36888624 Mon Sep 17 00:00:00 2001 From: ve-sdk-ios Date: Fri, 1 Mar 2024 11:00:32 +0300 Subject: [PATCH 1/2] Video and photo modes for VE --- Example/Example/VideoEditorModule.swift | 14 +++++++--- Example/Example/ViewController.swift | 34 ++++++++++++++++++++----- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/Example/Example/VideoEditorModule.swift b/Example/Example/VideoEditorModule.swift index 446fcedc..1dc170dd 100644 --- a/Example/Example/VideoEditorModule.swift +++ b/Example/Example/VideoEditorModule.swift @@ -19,8 +19,8 @@ class VideoEditorModule { var isVideoEditorInitialized: Bool { videoEditorSDK != nil } - init(token: String) { - let config = createConfiguration() + init(token: String, videoEditorMode: BanubaVideoEditorMode) { + let config = createConfiguration(videoEditorMode: videoEditorMode) let externalViewControllerFactory = createExampleExternalViewControllerFactory() let videoEditorSDK = BanubaVideoEditor( @@ -72,7 +72,7 @@ class VideoEditorModule { return progressViewController } - func createConfiguration() -> VideoEditorConfig { + func createConfiguration(videoEditorMode: BanubaVideoEditorMode) -> VideoEditorConfig { var config = VideoEditorConfig() config.setupColorsPalette( @@ -105,6 +105,14 @@ class VideoEditorModule { featureConfiguration.isMuteCameraAudioEnabled = true config.updateFeatureConfiguration(featureConfiguration: featureConfiguration) + switch videoEditorMode { + case .video: + config.recorderConfiguration.captureButtonModes = [.video] + case .photo: + config.recorderConfiguration.captureButtonModes = [.photo] + config.recorderConfiguration.additionalEffectsButtons = config.recorderConfiguration.additionalEffectsButtons.filter { $0.identifier != .sound } + } + return config } diff --git a/Example/Example/ViewController.swift b/Example/Example/ViewController.swift index b583d906..3d6b5fd3 100644 --- a/Example/Example/ViewController.swift +++ b/Example/Example/ViewController.swift @@ -11,6 +11,11 @@ import VEExportSDK import BanubaAudioBrowserSDK import BanubaLicenseServicingSDK +enum BanubaVideoEditorMode: String, CaseIterable { + case video + case photo +} + class ViewController: UIViewController, BanubaVideoEditorDelegate, BanubaPhotoEditorDelegate { // MARK: - IBOutlet @@ -51,7 +56,7 @@ class ViewController: UIViewController, BanubaVideoEditorDelegate, BanubaPhotoEd musicTrack: musicTrackPreset, // Paste a music track as a track preset at the camera screen to record video with music animated: true ) - checkLicenseAndOpenVideoEditor(with: launchConfig) + selectVideoEditorModeAndLaunchVE(with: launchConfig) } @IBAction func openVideoEditorPiP(_ sender: Any) { @@ -66,7 +71,7 @@ class ViewController: UIViewController, BanubaVideoEditorDelegate, BanubaPhotoEd animated: true ) - self.checkLicenseAndOpenVideoEditor(with: launchConfig) + self.checkLicenseAndOpenVideoEditor(with: launchConfig, videoEditorMode: .video) } } @@ -77,7 +82,7 @@ class ViewController: UIViewController, BanubaVideoEditorDelegate, BanubaPhotoEd animated: true ) - checkLicenseAndOpenVideoEditor(with: launchConfig) + checkLicenseAndOpenVideoEditor(with: launchConfig, videoEditorMode: .video) } @IBAction func openVideoEditorTrimmer(_ sender: UIButton) { @@ -92,7 +97,7 @@ class ViewController: UIViewController, BanubaVideoEditorDelegate, BanubaPhotoEd animated: true ) - self.checkLicenseAndOpenVideoEditor(with: launchConfig) + self.checkLicenseAndOpenVideoEditor(with: launchConfig, videoEditorMode: .video) } } @@ -104,6 +109,23 @@ class ViewController: UIViewController, BanubaVideoEditorDelegate, BanubaPhotoEd checkLicenseAndOpenPhotoEditor(with: launchConfig) } + private func selectVideoEditorModeAndLaunchVE(with launchConfig: VideoEditorLaunchConfig) { + let alertController = UIAlertController(title: "Select Video Editor Mode", message: nil, preferredStyle: .alert) + BanubaVideoEditorMode.allCases.forEach { mode in + alertController.addAction( + UIAlertAction( + title: mode.rawValue, + style: .default, + handler: { [weak self] _ in + self?.checkLicenseAndOpenVideoEditor(with: launchConfig, videoEditorMode: mode) + } + ) + ) + } + + present(alertController, animated: true) + } + @IBAction func openPhotoEditorFromEditor(_ sender: UIButton) { pickGalleryPhoto() { assets in guard let asset = assets?.first else { @@ -183,13 +205,13 @@ class ViewController: UIViewController, BanubaVideoEditorDelegate, BanubaPhotoEd return musicTrackPreset } - private func checkLicenseAndOpenVideoEditor(with launchConfig: VideoEditorLaunchConfig) { + private func checkLicenseAndOpenVideoEditor(with launchConfig: VideoEditorLaunchConfig, videoEditorMode: BanubaVideoEditorMode) { // Deallocate any active instances of both editors to free used resources // and to prevent "You are trying to create the second instance of the singleton." crash photoEditorModule = nil videoEditorModule = nil - videoEditorModule = VideoEditorModule(token: AppDelegate.licenseToken) + videoEditorModule = VideoEditorModule(token: AppDelegate.licenseToken, videoEditorMode: videoEditorMode) guard let videoEditorSDK = videoEditorModule?.videoEditorSDK else { invalidTokenMessageLabel.text = "Banuba Video Editor SDK is not initialized: license token is unknown or incorrect.\nPlease check your license token or contact Banuba" From 08795fd515a04c1a037f2c73e03ad0bf479daa74 Mon Sep 17 00:00:00 2001 From: ve-sdk-ios Date: Fri, 1 Mar 2024 11:05:07 +0300 Subject: [PATCH 2/2] refactoring --- Example/Example/VideoEditorModule.swift | 5 +++++ Example/Example/ViewController.swift | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Example/Example/VideoEditorModule.swift b/Example/Example/VideoEditorModule.swift index 1dc170dd..2cdc3f3b 100644 --- a/Example/Example/VideoEditorModule.swift +++ b/Example/Example/VideoEditorModule.swift @@ -10,6 +10,11 @@ import BSImagePicker import VEExportSDK import BanubaAudioBrowserSDK +enum BanubaVideoEditorMode: String, CaseIterable { + case video + case photo +} + // Adopting CountdownView to using in BanubaVideoEditorSDK extension CountdownView: MusicEditorCountdownAnimatableView {} diff --git a/Example/Example/ViewController.swift b/Example/Example/ViewController.swift index 3d6b5fd3..50cc6b2f 100644 --- a/Example/Example/ViewController.swift +++ b/Example/Example/ViewController.swift @@ -11,11 +11,6 @@ import VEExportSDK import BanubaAudioBrowserSDK import BanubaLicenseServicingSDK -enum BanubaVideoEditorMode: String, CaseIterable { - case video - case photo -} - class ViewController: UIViewController, BanubaVideoEditorDelegate, BanubaPhotoEditorDelegate { // MARK: - IBOutlet