@@ -4,10 +4,12 @@ import android.app.Activity
4
4
import android.content.Intent
5
5
import android.net.Uri
6
6
import android.util.Log
7
+ import androidx.annotation.WorkerThread
7
8
import com.facebook.react.bridge.*
8
9
import ly.img.android.IMGLY
9
10
import ly.img.android.VESDK
10
11
import ly.img.android.pesdk.VideoEditorSettingsList
12
+ import ly.img.android.pesdk.backend.decoder.VideoSource
11
13
import ly.img.android.pesdk.backend.model.state.LoadSettings
12
14
import ly.img.android.pesdk.backend.model.state.manager.SettingsList
13
15
import ly.img.android.pesdk.kotlin_extension.continueWithExceptions
@@ -23,16 +25,23 @@ import java.io.File
23
25
import ly.img.android.pesdk.backend.encoder.Encoder
24
26
import ly.img.android.pesdk.backend.model.EditorSDKResult
25
27
import ly.img.android.pesdk.backend.model.VideoPart
26
- import ly.img.android.pesdk.backend.model.state.LoadState
27
28
import ly.img.android.pesdk.backend.model.state.VideoCompositionSettings
29
+ import ly.img.android.pesdk.backend.model.state.manager.StateHandler
30
+ import ly.img.android.pesdk.ui.activity.VideoEditorActivity
28
31
import ly.img.android.serializer._3.IMGLYFileReader
29
32
import ly.img.android.serializer._3.IMGLYFileWriter
30
33
import java.util.UUID
31
34
32
35
class RNVideoEditorSDKModule (reactContext : ReactApplicationContext ) : ReactContextBaseJavaModule(reactContext), ActivityEventListener {
33
36
companion object {
34
37
// This number must be unique. It is public to allow client code to change it if the same value is used elsewhere.
35
- var EDITOR_RESULT_ID = 29065
38
+ @JvmField var EDITOR_RESULT_ID = 29065
39
+
40
+ /* * A closure to modify a *VideoEditorSettingsList* before the editor is opened. */
41
+ @JvmField var editorWillOpenClosure: ((settingsList: VideoEditorSettingsList ) -> Unit )? = null
42
+
43
+ /* * A closure allowing access to the *StateHandler* before the editor is exporting. */
44
+ @JvmField var editorWillExportClosure: ((stateHandler: StateHandler ) -> Unit )? = null
36
45
}
37
46
38
47
init {
@@ -62,9 +71,9 @@ class RNVideoEditorSDKModule(reactContext: ReactApplicationContext) : ReactConte
62
71
63
72
override fun onActivityResult (activity : Activity , requestCode : Int , resultCode : Int , intent : Intent ? ) {
64
73
val data = try {
65
- intent?.let { EditorSDKResult (it) }
74
+ intent?.let { EditorSDKResult (it) }
66
75
} catch (e: EditorSDKResult .NotAnImglyResultException ) {
67
- null
76
+ null
68
77
} ? : return // If data is null the result is not from us.
69
78
70
79
when (requestCode) {
@@ -128,10 +137,10 @@ class RNVideoEditorSDKModule(reactContext: ReactApplicationContext) : ReactConte
128
137
}
129
138
130
139
var segments: ReadableArray ? = null
131
- val canvasSize = settingsList[ LoadState :: class ].sourceSize
140
+ val canvasSize = sourcePath?. let { VideoSource .create(it).fetchFormatInfo()?.size }
132
141
val serializedSize = reactMap(
133
- " height" to canvasSize.height,
134
- " width" to canvasSize.width
142
+ " height" to canvasSize? .height,
143
+ " width" to canvasSize? .width
135
144
)
136
145
137
146
if (resolveManually) {
@@ -166,8 +175,9 @@ class RNVideoEditorSDKModule(reactContext: ReactApplicationContext) : ReactConte
166
175
@ReactMethod
167
176
fun present (video : String , config : ReadableMap ? , serialization : String? , promise : Promise ) {
168
177
val configuration = ConfigLoader .readFrom(config?.toHashMap() ? : mapOf ())
169
- val exportVideoSegments = config?.getMap(" export" )?.getMap(" video" )?.getBoolean(" segments" ) == true
170
- val createTemporaryFiles = configuration.export?.serialization?.enabled == true || exportVideoSegments
178
+ val serializationEnabled = configuration.export?.serialization?.enabled == true
179
+ val exportVideoSegments = configuration.export?.video?.segments == true
180
+ val createTemporaryFiles = serializationEnabled || exportVideoSegments
171
181
resolveManually = exportVideoSegments
172
182
173
183
val settingsList = VideoEditorSettingsList (createTemporaryFiles)
@@ -189,9 +199,9 @@ class RNVideoEditorSDKModule(reactContext: ReactApplicationContext) : ReactConte
189
199
var source = resolveSize(size)
190
200
191
201
val configuration = ConfigLoader .readFrom(config?.toHashMap() ? : mapOf ())
192
-
193
- val exportVideoSegments = config?.getMap( " export" )?.getMap( " video" )?.getBoolean( " segments" ) == true
194
- val createTemporaryFiles = configuration.export?.serialization?.enabled == true || exportVideoSegments
202
+ val serializationEnabled = configuration.export?.serialization?.enabled == true
203
+ val exportVideoSegments = configuration. export?. video?. segments == true
204
+ val createTemporaryFiles = serializationEnabled || exportVideoSegments
195
205
resolveManually = exportVideoSegments
196
206
197
207
val settingsList = VideoEditorSettingsList (createTemporaryFiles)
@@ -296,7 +306,9 @@ class RNVideoEditorSDKModule(reactContext: ReactApplicationContext) : ReactConte
296
306
return LoadSettings .compositionSource(width.toInt(), height.toInt(), 60 )
297
307
}
298
308
299
- private fun readSerialisation (settingsList : SettingsList , serialization : String? , readImage : Boolean ) {
309
+ private fun readSerialisation (settingsList : VideoEditorSettingsList , serialization : String? , readImage : Boolean ) {
310
+ editorWillOpenClosure?.invoke(settingsList)
311
+
300
312
if (serialization != null ) {
301
313
skipIfNotExists {
302
314
IMGLYFileReader (settingsList).also {
@@ -308,12 +320,13 @@ class RNVideoEditorSDKModule(reactContext: ReactApplicationContext) : ReactConte
308
320
309
321
private fun startEditor (settingsList : VideoEditorSettingsList ? ) {
310
322
val currentActivity = this .currentActivity ? : throw RuntimeException (" Can't start the Editor because there is no current activity" )
311
- currentEditorUID = UUID .randomUUID().toString()
312
323
if (settingsList != null ) {
324
+ currentEditorUID = UUID .randomUUID().toString()
325
+
313
326
MainThreadRunnable {
314
- VideoEditorBuilder (currentActivity)
315
- .setSettingsList(settingsList)
316
- .startActivityForResult(currentActivity, EDITOR_RESULT_ID )
327
+ VideoEditorBuilder (currentActivity, RNVideoEditorSDKActivity :: class .java )
328
+ .setSettingsList(settingsList)
329
+ .startActivityForResult(currentActivity, EDITOR_RESULT_ID )
317
330
settingsList.release()
318
331
}()
319
332
}
@@ -417,4 +430,14 @@ class RNVideoEditorSDKModule(reactContext: ReactApplicationContext) : ReactConte
417
430
}
418
431
419
432
override fun getName () = " RNVideoEditorSDK"
420
- }
433
+ }
434
+
435
+ /* * A *VideoEditorActivity* used for the native interfaces. */
436
+ class RNVideoEditorSDKActivity : VideoEditorActivity () {
437
+ @WorkerThread
438
+ override fun onExportStart (stateHandler : StateHandler ) {
439
+ RNVideoEditorSDKModule .editorWillExportClosure?.invoke(stateHandler)
440
+
441
+ super .onExportStart(stateHandler)
442
+ }
443
+ }
0 commit comments