-
Notifications
You must be signed in to change notification settings - Fork 16
/
AppDelegate.swift
172 lines (150 loc) · 7.16 KB
/
AppDelegate.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import UIKit
import Flutter
import AVKit
import BanubaAudioBrowserSDK
import BanubaPhotoEditorSDK
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
/*
true - uses custom audio browser implementation in this sample.
false - to keep default implementation.
*/
private let configEnableCustomAudioBrowser = false
lazy var audioBrowserFlutterEngine = FlutterEngine(name: "audioBrowserEngine")
// Video Editor Methods
static let methodInitVideoEditor = "initVideoEditor"
static let methodStartVideoEditor = "startVideoEditor"
static let methodStartVideoEditorPIP = "startVideoEditorPIP"
static let methodStartVideoEditorTrimmer = "startVideoEditorTrimmer"
static let methodDemoPlayExportedVideo = "playExportedVideo"
static let argExportedVideoFile = "argExportedVideoFilePath"
static let argExportedVideoCoverPreviewPath = "argExportedVideoCoverPreviewPath"
// Photo Editor Methods
static let methodInitPhotoEditor = "initPhotoEditor"
static let methodStartPhotoEditor = "startPhotoEditor"
static let argExportedPhotoFile = "argExportedPhotoFilePath"
static let errEditorNotInitialized = "ERR_SDK_NOT_INITIALIZED"
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
let videoEditor = VideoEditorModule()
var photoEditor: PhotoEditorModule?
if let controller = window?.rootViewController as? FlutterViewController,
let binaryMessenger = controller as? FlutterBinaryMessenger {
let channel = FlutterMethodChannel(
name: "banubaSdkChannel",
binaryMessenger: binaryMessenger
)
channel.setMethodCallHandler { methodCall, result in
let call = methodCall.method
switch call {
case AppDelegate.methodInitVideoEditor:
let token = methodCall.arguments as? String
videoEditor.initVideoEditor(
token: token,
flutterResult: result
)
case AppDelegate.methodStartVideoEditor:
videoEditor.openVideoEditorDefault(
fromViewController: controller,
flutterResult: result
)
case AppDelegate.methodStartVideoEditorPIP:
let pipVideoFilePath = methodCall.arguments as? String
if let videoFilePath = pipVideoFilePath {
videoEditor.openVideoEditorPIP(
fromViewController: controller,
videoURL: URL(fileURLWithPath: videoFilePath),
flutterResult: result
)
} else {
print("Cannot start video editor in PIP mode: missing or invalid video!")
result(FlutterError(code: "ERR_START_PIP_MISSING_VIDEO", message: "", details: nil))
}
case AppDelegate.methodDemoPlayExportedVideo:
/*
NOT REQUIRED FOR INTEGRATION
Added for playing exported video file.
*/
let demoPlayVideoFilePath = methodCall.arguments as? String
if let videoFilePath = demoPlayVideoFilePath {
self.demoPlayExportedVideo(controller: controller, videoURL: URL(fileURLWithPath: videoFilePath))
} else {
result(FlutterError(code: "ERR_EXPORT_PLAY_MISSING_VIDEO", message: "", details: nil))
}
case AppDelegate.methodStartVideoEditorTrimmer:
let trimmerVideoFilePath = methodCall.arguments as? String
if let videoFilePath = trimmerVideoFilePath {
videoEditor.openVideoEditorTrimmer(
fromViewController: controller,
videoURL: URL(fileURLWithPath: videoFilePath),
flutterResult: result
)
} else {
print("Cannot start video editor in trimmer mode: missing or invalid video!")
result(FlutterError(code: "ERR_START_TRIMMER_MISSING_VIDEO", message: "", details: nil))
}
case AppDelegate.methodStartPhotoEditor:
guard let token = methodCall.arguments as? String else {
print("Missing token")
return
}
photoEditor = PhotoEditorModule(
token: token,
flutterResult: result
)
case AppDelegate.methodStartPhotoEditor:
if let photoEditor = photoEditor {
photoEditor.presentPhotoEditor(
fromViewController: controller,
flutterResult: result
)
} else {
print("The Photo Editor is not initialized")
result(FlutterError(code: AppDelegate.errEditorNotInitialized, message: "", details: nil))
}
default:
print("Flutter method is not implemented on platform.")
result(FlutterMethodNotImplemented)
}
}
}
GeneratedPluginRegistrant.register(with: self)
// Register audio browser engine
audioBrowserFlutterEngine.run(withEntrypoint: "audioBrowser")
GeneratedPluginRegistrant.register(with: audioBrowserFlutterEngine)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
// Custom View Factory is used to provide you custom UI/UX experience in Video Editor SDK
// i.e. custom audio browser
func provideCustomViewFactory() -> FlutterCustomViewFactory? {
let factory: FlutterCustomViewFactory?
if configEnableCustomAudioBrowser {
factory = FlutterCustomViewFactory()
} else {
// Set your Mubert Api key here
let mubertApiLicense = ""
let mubertApiKey = ""
AudioBrowserConfig.shared.musicSource = .allSources
BanubaAudioBrowser.setMubertKeys(
license: mubertApiLicense,
token: mubertApiKey
)
factory = nil
}
return factory
}
/*
NOT REQUIRED FOR INTEGRATION
Added for playing exported video file.
*/
private func demoPlayExportedVideo(controller: FlutterViewController, videoURL: URL) {
let player = AVPlayer(url: videoURL)
let vc = AVPlayerViewController()
vc.player = player
controller.present(vc, animated: true) {
vc.player?.play()
}
}
}