@@ -4,7 +4,7 @@ import ImglyKit
4
4
import imgly_sdk
5
5
import AVFoundation
6
6
7
- @available ( iOS 9 . 0 , * )
7
+ @available ( iOS 13 . 0 , * )
8
8
public class FlutterVESDK : FlutterIMGLY , FlutterPlugin , VideoEditViewControllerDelegate {
9
9
10
10
// MARK: - Typealias
@@ -111,7 +111,7 @@ public class FlutterVESDK: FlutterIMGLY, FlutterPlugin, VideoEditViewControllerD
111
111
var videoEditViewController : VideoEditViewController
112
112
113
113
if let _serialization = serializationData {
114
- let deserializationResult = Deserializer . deserialize ( data: _serialization, imageDimensions: video. size, assetCatalog: configurationData? . assetCatalog ?? . shared )
114
+ let deserializationResult = Deserializer . deserialize ( data: _serialization, imageDimensions: video. size, assetCatalog: configurationData? . assetCatalog ?? . defaultItems )
115
115
photoEditModel = deserializationResult. model ?? photoEditModel
116
116
}
117
117
@@ -164,59 +164,62 @@ public class FlutterVESDK: FlutterIMGLY, FlutterPlugin, VideoEditViewControllerD
164
164
return ( nil , true )
165
165
}
166
166
}
167
+
168
+ private func handleError( _ videoEditViewController: VideoEditViewController , code: String , message: String ? , details: Any ? ) {
169
+ self . dismiss ( mediaEditViewController: videoEditViewController, animated: true ) {
170
+ self . result ? ( FlutterError ( code: code, message: message, details: details) )
171
+ self . result = nil
172
+ }
173
+ }
167
174
}
168
175
169
- @available ( iOS 9 . 0 , * )
176
+ @available ( iOS 13 . 0 , * )
170
177
extension FlutterVESDK {
171
-
172
178
/// Called if the video has been successfully exported.
173
179
/// - Parameter videoEditViewController: The instance of `VideoEditViewController` that finished exporting
174
- /// - Parameter url: The `URL` where the video has been exported to.
175
- public func videoEditViewController( _ videoEditViewController: VideoEditViewController , didFinishWithVideoAt url: URL ? ) {
176
-
180
+ /// - Parameter result: The `VideoEditorResult` from the editor.
181
+ public func videoEditViewControllerDidFinish( _ videoEditViewController: VideoEditViewController , result: VideoEditorResult ) {
177
182
var serialization : Any ?
178
183
179
184
if self . serializationEnabled == true {
180
185
guard let serializationData = videoEditViewController. serializedSettings else {
186
+ self . handleError ( videoEditViewController, code: " Serialization failed. " , message: " No serialization data found. " , details: nil )
181
187
return
182
188
}
183
189
if self . serializationType == IMGLYConstants . kExportTypeFileURL {
184
190
guard let exportURL = self . serializationFile else {
185
- self . result ? ( FlutterError ( code: " Serialization failed. " , message: " The URL must not be nil. " , details: nil ) )
186
- self . result = nil
191
+ self . handleError ( videoEditViewController, code: " Serialization failed. " , message: " The URL must not be nil. " , details: nil )
187
192
return
188
193
}
189
194
do {
190
195
try serializationData. IMGLYwriteToUrl ( exportURL, andCreateDirectoryIfNeeded: true )
191
196
serialization = self . serializationFile? . absoluteString
192
197
} catch let error {
193
- self . result ? ( FlutterError ( code: " Serialization failed. " , message: error. localizedDescription, details: error) )
194
- self . result = nil
198
+ self . handleError ( videoEditViewController , code: " Serialization failed. " , message: error. localizedDescription, details: error)
199
+ return
195
200
}
196
201
} else if self . serializationType == IMGLYConstants . kExportTypeObject {
197
202
do {
198
203
serialization = try JSONSerialization . jsonObject ( with: serializationData, options: . init( rawValue: 0 ) )
199
204
} catch let error {
200
- self . result ? ( FlutterError ( code: " Serialization failed. " , message: error. localizedDescription, details: error) )
201
- self . result = nil
205
+ self . handleError ( videoEditViewController , code: " Serialization failed. " , message: error. localizedDescription, details: error)
206
+ return
202
207
}
203
208
}
204
209
}
205
210
206
211
self . dismiss ( mediaEditViewController: videoEditViewController, animated: true ) {
207
- let res : [ String : Any ? ] = [ " video " : url? . absoluteString, " hasChanges " : videoEditViewController . hasChanges , " serialization " : serialization]
212
+ let res : [ String : Any ? ] = [ " video " : result . output . url. absoluteString, " hasChanges " : result . status == . renderedWithChanges , " serialization " : serialization]
208
213
self . result ? ( res)
209
214
self . result = nil
210
215
}
211
216
}
212
217
213
218
/// Called if the `VideoEditViewController` failed to export the video.
214
219
/// - Parameter videoEditViewController: The `VideoEditViewController` that failed to export the video.
215
- public func videoEditViewControllerDidFailToGenerateVideo( _ videoEditViewController: VideoEditViewController ) {
216
- self . dismiss ( mediaEditViewController: videoEditViewController, animated: true ) {
217
- self . result ? ( FlutterError ( code: " editor_failed " , message: " The editor did fail to generate the video. " , details: nil ) )
218
- self . result = nil
219
- }
220
+ /// - Parameter error: The `VideoEditorError` that caused the failure.
221
+ public func videoEditViewControllerDidFail( _ videoEditViewController: VideoEditViewController , error: VideoEditorError ) {
222
+ self . handleError ( videoEditViewController, code: " Editor failed " , message: " The editor did fail to generate the video. " , details: error)
220
223
}
221
224
222
225
/// Called if the `VideoEditViewController` was cancelled.
0 commit comments