-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.dart
More file actions
258 lines (227 loc) · 8.13 KB
/
main.dart
File metadata and controls
258 lines (227 loc) · 8.13 KB
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:ve_sdk_flutter/export_data.dart';
import 'package:flutter/services.dart';
import 'package:image_picker/image_picker.dart';
import 'package:ve_sdk_flutter/export_result.dart';
import 'package:ve_sdk_flutter/features_config.dart';
import 'package:ve_sdk_flutter/ve_sdk_flutter.dart';
const _licenseToken = SET UP YOUR LICENSE TOKEN;
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
final _veSdkFlutterPlugin = VeSdkFlutter();
String _errorMessage = '';
Future<void> _startVideoEditorInCameraMode() async {
// Specify your Config params in the builder below
final config = FeaturesConfigBuilder()
// .setCaptions(...)
// ...
.build();
// Export data example
// const exportData = ExportData(exportedVideos: [
// ExportedVideo(
// fileName: "export_HD",
// videoResolution: VideoResolution.hd720p
// )],
// watermark: Watermark(
// imagePath: "assets/watermark.png",
// alignment: WatermarkAlignment.topLeft
// )
// );
try {
dynamic exportResult = await _veSdkFlutterPlugin
.openCameraScreen(_licenseToken, config);
_handleExportResult(exportResult);
} on PlatformException catch (e) {
_handlePlatformException(e);
}
}
Future<void> _startVideoEditorInPipMode() async {
// Specify your Config params in the builder below
final config = FeaturesConfigBuilder()
// .setAudioBrowser(...)
// ...
.build();
final ImagePicker picker = ImagePicker();
final videoFile = await picker.pickVideo(source: ImageSource.gallery);
final sourceVideoFile = videoFile?.path;
if (sourceVideoFile == null) {
debugPrint('Error: Cannot start video editor in pip mode: please pick video file');
return;
}
try {
dynamic exportResult = await _veSdkFlutterPlugin.openPipScreen(
_licenseToken, config, sourceVideoFile);
_handleExportResult(exportResult);
} on PlatformException catch (e) {
_handlePlatformException(e);
}
}
Future<void> _startVideoEditorInTrimmerMode() async {
// Specify your Config params in the builder below
final config = FeaturesConfigBuilder()
// .setDraftConfig(...)
//...
.build();
final ImagePicker picker = ImagePicker();
final videoFiles = await picker.pickMultipleMedia(imageQuality: 3);
if (videoFiles.isEmpty) {
debugPrint('Error: Cannot start video editor in trimmer mode: please pick video files');
return;
}
final sources = videoFiles.map((f) => f.path).toList();
try {
dynamic exportResult = await _veSdkFlutterPlugin.openTrimmerScreen(
_licenseToken, config, sources);
_handleExportResult(exportResult);
} on PlatformException catch (e) {
_handlePlatformException(e);
}
}
void _handleExportResult(ExportResult? result) {
if (result == null) {
debugPrint('No export result! The user has closed video editor before export');
return;
}
// The list of exported video file paths
debugPrint('Exported video files = ${result.videoSources}');
// Preview as a image file taken by the user. Null - when preview screen is disabled.
debugPrint('Exported preview file = ${result.previewFilePath}');
// Meta file where you can find short data used in exported video
debugPrint('Exported meta file = ${result.metaFilePath}');
}
void _handlePlatformException(PlatformException exception) {
_errorMessage = exception.message ?? 'unknown error';
// You can find error codes 'package:ve_sdk_flutter/errors.dart';
debugPrint("Error: code = ${exception.code}, message = $_errorMessage");
setState(() {});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.black38,
centerTitle: true,
title: const Text("Video Editor Flutter plugin"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Expanded(
flex: 1,
child: Center(
child: Padding(
padding: EdgeInsets.all(15.0),
child: Text(
'The plugin demonstrates how to use Banuba Video Editor',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 17.0,
),
),
),
),
),
Expanded(
flex: 2,
child: Column(
children: [
Visibility(
visible: _errorMessage.isNotEmpty,
child: Text(
_errorMessage,
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 17.0, color: Colors.red),
),
),
const SizedBox(height: 20),
ElevatedButton(
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white,
backgroundColor: Colors.blueAccent,
shadowColor: Colors.blueGrey,
elevation: 10,
fixedSize: const Size(300, 50),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
),
onPressed: () => _startVideoEditorInCameraMode(),
child: const Text(
'Open Video Editor - Camera screen',
style: TextStyle(
fontSize: 14.0,
),
),
),
const SizedBox(height: 20),
ElevatedButton(
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white,
backgroundColor: Colors.blueAccent,
shadowColor: Colors.blueGrey,
elevation: 10,
fixedSize: const Size(300, 50),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
),
onPressed: () => _startVideoEditorInPipMode(),
child: const Text(
'Open Video Editor - PIP screen ',
style: TextStyle(
fontSize: 14.0,
),
),
),
const SizedBox(height: 20),
ElevatedButton(
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white,
backgroundColor: Colors.blueAccent,
shadowColor: Colors.blueGrey,
elevation: 10,
fixedSize: const Size(300, 50),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
),
onPressed: () => _startVideoEditorInTrimmerMode(),
child: const Text(
'Open Video Editor - Trimmer screen',
style: TextStyle(
fontSize: 14.0,
),
),
),
],
),
)
],
),
),
);
}
}