From be605cf2ae1c877cceb96ea9735438422f3bb86d Mon Sep 17 00:00:00 2001 From: Gleb Prischepa Date: Thu, 11 Apr 2024 17:29:54 +0300 Subject: [PATCH 1/2] Pass params to customize VE on Android --- .../flutter/flutter_ve_sdk/MainActivity.kt | 6 ++-- .../flutter_ve_sdk/VideoEditorModule.kt | 30 +++++++++++++++++-- lib/main.dart | 11 ++++++- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/android/app/src/main/kotlin/com/banuba/flutter/flutter_ve_sdk/MainActivity.kt b/android/app/src/main/kotlin/com/banuba/flutter/flutter_ve_sdk/MainActivity.kt index 267b624..90afc5e 100644 --- a/android/app/src/main/kotlin/com/banuba/flutter/flutter_ve_sdk/MainActivity.kt +++ b/android/app/src/main/kotlin/com/banuba/flutter/flutter_ve_sdk/MainActivity.kt @@ -69,7 +69,8 @@ class MainActivity : FlutterActivity() { when (call.method) { METHOD_INIT_VIDEO_EDITOR -> { - val licenseToken = call.arguments as String + val params = call.arguments as HashMap + val licenseToken = params["banubaToken"] as String editorSDK = BanubaVideoEditor.initialize(licenseToken) if (editorSDK == null) { @@ -79,7 +80,8 @@ class MainActivity : FlutterActivity() { if (videoEditorModule == null) { // Initialize video editor sdk dependencies videoEditorModule = VideoEditorModule().apply { - initialize(application) + // Pass params to initializer + initialize(application, params) } } result.success(null) diff --git a/android/app/src/main/kotlin/com/banuba/flutter/flutter_ve_sdk/VideoEditorModule.kt b/android/app/src/main/kotlin/com/banuba/flutter/flutter_ve_sdk/VideoEditorModule.kt index 9f317ca..89c6e09 100644 --- a/android/app/src/main/kotlin/com/banuba/flutter/flutter_ve_sdk/VideoEditorModule.kt +++ b/android/app/src/main/kotlin/com/banuba/flutter/flutter_ve_sdk/VideoEditorModule.kt @@ -6,6 +6,7 @@ import com.banuba.sdk.arcloud.data.source.ArEffectsRepositoryProvider import com.banuba.sdk.arcloud.di.ArCloudKoinModule import com.banuba.sdk.audiobrowser.di.AudioBrowserKoinModule import com.banuba.sdk.audiobrowser.domain.AudioBrowserMusicProvider +import com.banuba.sdk.cameraui.data.CameraConfig import com.banuba.sdk.core.data.TrackData import com.banuba.sdk.core.ui.ContentFeatureProvider import com.banuba.sdk.effectplayer.adapter.BanubaEffectPlayerKoinModule @@ -22,7 +23,10 @@ import org.koin.dsl.module class VideoEditorModule { - fun initialize(application: Application) { + fun initialize( + application: Application, + params: HashMap + ) { startKoin { androidContext(application) allowOverride(true) @@ -45,7 +49,7 @@ class VideoEditorModule { GalleryKoinModule().module, // Sample integration module - SampleIntegrationVeKoinModule().module, + SampleIntegrationVeKoinModule(params).module, ) } } @@ -57,7 +61,7 @@ class VideoEditorModule { * Some dependencies has no default implementations. It means that * these classes fully depends on your requirements */ -private class SampleIntegrationVeKoinModule { +private class SampleIntegrationVeKoinModule(private val params: HashMap) { val module = module { single(createdAtStart = true) { @@ -79,5 +83,25 @@ private class SampleIntegrationVeKoinModule { AudioBrowserMusicProvider() } } + + single { + val durations = (params["cameraVideoDurations"] as? List)?.mapNotNull { + if (it is Number) { + it.toLong() + } else { + null + } + } + + if (durations == null) { + val defaultConfig = CameraConfig() + defaultConfig + } else { + CameraConfig( + videoDurations = durations, + maxRecordedTotalVideoDurationMs = durations[0] + ) + } + } } } \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index ace84ee..a9ce2a6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,3 +1,5 @@ +import 'dart:ffi'; + import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_linkify/flutter_linkify.dart'; @@ -77,7 +79,14 @@ class _MyHomePageState extends State { } Future _initVideoEditor() async { - await platformChannel.invokeMethod(methodInitVideoEditor, LICENSE_TOKEN); + // Create params + final params = { + 'banubaToken': LICENSE_TOKEN, + 'cameraVideoDurations': [30000, 20000, 10000, 5000], // 30, 20, 10, 5 seconds + }; + + // Pass params to platforms + await platformChannel.invokeMethod(methodInitVideoEditor, params); } Future _startVideoEditorDefault() async { From 01141ce2e55e86c79e2cd4b00561dc70a1da9e4a Mon Sep 17 00:00:00 2001 From: Rostyslav <> Date: Fri, 12 Apr 2024 14:38:04 +0300 Subject: [PATCH 2/2] iOS part. --- ios/Runner/AppDelegate.swift | 18 ++++++++++---- ios/Runner/VideoEditorModule.swift | 38 ++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift index 4046891..6399f3f 100644 --- a/ios/Runner/AppDelegate.swift +++ b/ios/Runner/AppDelegate.swift @@ -50,11 +50,19 @@ import BanubaPhotoEditorSDK let call = methodCall.method switch call { case AppDelegate.methodInitVideoEditor: - let token = methodCall.arguments as? String - videoEditor.initVideoEditor( - token: token, - flutterResult: result - ) + if let parameters = methodCall.arguments as? [String: Any], + let token = parameters["banubaToken"] as? String, + let durations = parameters["cameraVideoDurations"] as? [Double] { + videoEditor.initVideoEditor( + token: token, + // Convert milliseconds to seconds + videoDurations: durations.map { $0 / 1000 }, + flutterResult: result + ) + } else { + print("Cannot start video editor: missing token or video durations") + result(FlutterError(code: AppDelegate.errEditorNotInitialized, message: "", details: nil)) + } case AppDelegate.methodStartVideoEditor: videoEditor.openVideoEditorDefault( fromViewController: controller, diff --git a/ios/Runner/VideoEditorModule.swift b/ios/Runner/VideoEditorModule.swift index 51893d8..85099ab 100644 --- a/ios/Runner/VideoEditorModule.swift +++ b/ios/Runner/VideoEditorModule.swift @@ -24,18 +24,48 @@ class VideoEditorModule: VideoEditor { private let restoreLastVideoEditingSession: Bool = false func initVideoEditor( - token: String?, + token: String, + videoDurations: [TimeInterval], flutterResult: @escaping FlutterResult ) { - guard videoEditorSDK == nil else { - flutterResult(nil) - return + var config = VideoEditorConfig() + config.videoDurationConfiguration.videoDurations = videoDurations + if let maxDuration = videoDurations.first { + config.videoDurationConfiguration.maximumVideoDuration = maxDuration } + initVideoEditor( + token: token, + config: config, + flutterResult: flutterResult + ) + } + + func initVideoEditor( + token: String?, + flutterResult: @escaping FlutterResult + ) { let config = VideoEditorConfig() // Make customization here + initVideoEditor( + token: token, + config: config, + flutterResult: flutterResult + ) + } + + func initVideoEditor( + token: String?, + config: VideoEditorConfig, + flutterResult: @escaping FlutterResult + ) { + guard videoEditorSDK == nil else { + flutterResult(nil) + return + } + videoEditorSDK = BanubaVideoEditor( token: token ?? "", configuration: config,