-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathve_sdk_flutter_method_channel.dart
120 lines (107 loc) · 3.67 KB
/
ve_sdk_flutter_method_channel.dart
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
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:ve_sdk_flutter/export_data.dart';
import 'package:ve_sdk_flutter/export_data_serializer.dart';
import 'package:ve_sdk_flutter/features_config.dart';
import 'package:ve_sdk_flutter/features_config_serializer.dart';
import 'package:ve_sdk_flutter/export_result.dart';
import 've_sdk_flutter_platform_interface.dart';
/// An implementation of [VeSdkFlutterPlatform] that uses method channels.
class MethodChannelVeSdkFlutter extends VeSdkFlutterPlatform {
// Channel and method
static const String _channelName = 've_sdk_flutter';
static const String _methodStart = 'startVideoEditor';
// Screens
static const String _screenCamera = 'camera';
static const String _screenPip = 'pip';
static const String _screenTrimmer = 'trimmer';
// Input params
static const String _inputParamToken = 'token';
static const String _inputParamFeaturesConfig = 'featuresConfig';
static const String _inputParamExportData = 'exportData';
static const String _inputParamScreen = 'screen';
static const String _inputParamVideoSources = 'videoSources';
// Exported params
static const String _exportedVideoSources = 'exportedVideoSources';
static const String _exportedPreview = 'exportedPreview';
static const String _exportedMeta = 'exportedMeta';
/// The method channel used to interact with the native platform.
@visibleForTesting
final methodChannel = const MethodChannel(_channelName);
@override
Future<ExportResult?> openCameraScreen(
String token,
FeaturesConfig featuresConfig,
{ExportData? exportData}
) => _open(
token,
featuresConfig,
_screenCamera,
[],
exportData: exportData
);
@override
Future<ExportResult?> openPipScreen(
String token,
FeaturesConfig featuresConfig,
String sourceVideoPath,
{ExportData? exportData}
) => _open(
token,
featuresConfig,
_screenPip,
[sourceVideoPath],
exportData: exportData
);
@override
Future<ExportResult?> openTrimmerScreen(
String token,
FeaturesConfig featuresConfig,
List<String> sourceVideoPathList,
{ExportData? exportData}
) => _open(
token,
featuresConfig,
_screenTrimmer,
sourceVideoPathList,
exportData: exportData
);
Future<ExportResult?> _open(
String token,
FeaturesConfig featuresConfig,
String screen,
List<String> sourceVideoPathList,
{ExportData? exportData}
) async {
if (featuresConfig.enableEditorV2 && screen == _screenTrimmer){
debugPrint("New UI is not available from Trimmer screen");
return null;
}
final inputParams = {
_inputParamToken: token,
_inputParamFeaturesConfig: featuresConfig.serialize(),
_inputParamScreen: screen,
_inputParamVideoSources: sourceVideoPathList,
_inputParamExportData: exportData?.serialize()
};
debugPrint('Start video editor with params = $inputParams');
dynamic exportedData =
await methodChannel.invokeMethod(_methodStart, inputParams);
if (exportedData == null) {
return null;
} else {
List<Object?> sources =
exportedData[_exportedVideoSources] as List<Object?>;
List<String> videoSources = sources
.where((element) => element != null)
.map((e) => e.toString())
.toList();
String? metaFilePath = exportedData[_exportedMeta];
String? previewFilePath = exportedData[_exportedPreview];
return ExportResult(
videoSources: videoSources,
previewFilePath: previewFilePath,
metaFilePath: metaFilePath);
}
}
}