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

Video and photo modes for VE #199

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions Example/Example/VideoEditorModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand All @@ -19,8 +24,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(
Expand Down Expand Up @@ -72,7 +77,7 @@ class VideoEditorModule {
return progressViewController
}

func createConfiguration() -> VideoEditorConfig {
func createConfiguration(videoEditorMode: BanubaVideoEditorMode) -> VideoEditorConfig {
var config = VideoEditorConfig()

config.setupColorsPalette(
Expand Down Expand Up @@ -105,6 +110,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
}

Expand Down
29 changes: 23 additions & 6 deletions Example/Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,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) {
Expand All @@ -66,7 +66,7 @@ class ViewController: UIViewController, BanubaVideoEditorDelegate, BanubaPhotoEd
animated: true
)

self.checkLicenseAndOpenVideoEditor(with: launchConfig)
self.checkLicenseAndOpenVideoEditor(with: launchConfig, videoEditorMode: .video)
}
}

Expand All @@ -77,7 +77,7 @@ class ViewController: UIViewController, BanubaVideoEditorDelegate, BanubaPhotoEd
animated: true
)

checkLicenseAndOpenVideoEditor(with: launchConfig)
checkLicenseAndOpenVideoEditor(with: launchConfig, videoEditorMode: .video)
}

@IBAction func openVideoEditorTrimmer(_ sender: UIButton) {
Expand All @@ -92,7 +92,7 @@ class ViewController: UIViewController, BanubaVideoEditorDelegate, BanubaPhotoEd
animated: true
)

self.checkLicenseAndOpenVideoEditor(with: launchConfig)
self.checkLicenseAndOpenVideoEditor(with: launchConfig, videoEditorMode: .video)
}
}

Expand All @@ -104,6 +104,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 {
Expand Down Expand Up @@ -183,13 +200,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"
Expand Down