react-native-video-trim 7.1.1 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,7 @@ package com.videotrim
3
3
  import com.facebook.react.bridge.Promise
4
4
  import com.facebook.react.bridge.ReactApplicationContext
5
5
  import com.facebook.react.bridge.ReactContextBaseJavaModule
6
+ import com.facebook.react.bridge.ReadableArray
6
7
  import com.facebook.react.bridge.ReadableMap
7
8
 
8
9
  abstract class VideoTrimSpec internal constructor(context: ReactApplicationContext) :
@@ -21,4 +22,20 @@ abstract class VideoTrimSpec internal constructor(context: ReactApplicationConte
21
22
  abstract fun isValidFile(url: String, promise: Promise)
22
23
 
23
24
  abstract fun trim(url: String, options: ReadableMap?, promise: Promise)
25
+
26
+ abstract fun getFrameAt(url: String, options: ReadableMap?, promise: Promise)
27
+
28
+ abstract fun extractAudio(url: String, options: ReadableMap?, promise: Promise)
29
+
30
+ abstract fun compress(url: String, options: ReadableMap?, promise: Promise)
31
+
32
+ abstract fun toGif(url: String, options: ReadableMap?, promise: Promise)
33
+
34
+ abstract fun merge(urls: ReadableArray, options: ReadableMap?, promise: Promise)
35
+
36
+ abstract fun saveToPhoto(filePath: String, promise: Promise)
37
+
38
+ abstract fun saveToDocuments(filePath: String, promise: Promise)
39
+
40
+ abstract fun share(filePath: String, promise: Promise)
24
41
  }
package/ios/VideoTrim.mm CHANGED
@@ -73,8 +73,10 @@ RCT_EXPORT_MODULE()
73
73
  dict[@"startTime"] = @(options.startTime());
74
74
  dict[@"endTime"] = @(options.endTime());
75
75
  dict[@"enablePreciseTrimming"] = @(options.enablePreciseTrimming());
76
+ dict[@"removeAudio"] = @(options.removeAudio());
77
+ dict[@"speed"] = @(options.speed());
76
78
 
77
- [self->videoTrim trim:url url:dict config:^(NSDictionary<NSString *,id> * _Nonnull result) {
79
+ [self->videoTrim trimWithInputFile:url config:dict completion:^(NSDictionary<NSString *,id> * _Nonnull result) {
78
80
  BOOL success = [result[@"success"] boolValue];
79
81
  if (success) {
80
82
  resolve(result);
@@ -143,6 +145,8 @@ RCT_EXPORT_MODULE()
143
145
  dict[@"alertOnFailMessage"] = config.alertOnFailMessage();
144
146
  dict[@"alertOnFailCloseText"] = config.alertOnFailCloseText();
145
147
  dict[@"enablePreciseTrimming"] = @(config.enablePreciseTrimming());
148
+ dict[@"removeAudio"] = @(config.removeAudio());
149
+ dict[@"speed"] = @(config.speed());
146
150
 
147
151
  // Handle optional color values
148
152
  auto trimmerColorOpt = config.trimmerColor();
@@ -190,9 +194,143 @@ RCT_EXPORT_MODULE()
190
194
  dict[@"theme"] = theme;
191
195
  }
192
196
 
197
+ NSString *durationFormat = config.durationFormat();
198
+ if (durationFormat != nil) {
199
+ dict[@"durationFormat"] = durationFormat;
200
+ }
201
+
193
202
  [self->videoTrim showEditor:filePath withConfig:dict];
194
203
  }
195
204
 
205
+ - (void)getFrameAt:(nonnull NSString *)url
206
+ options:(JS::NativeVideoTrim::FrameExtractionOptions &)options
207
+ resolve:(nonnull RCTPromiseResolveBlock)resolve
208
+ reject:(nonnull RCTPromiseRejectBlock)reject {
209
+ NSMutableDictionary *dict = [NSMutableDictionary dictionary];
210
+ dict[@"time"] = @(options.time());
211
+ dict[@"format"] = options.format();
212
+ dict[@"quality"] = @(options.quality());
213
+ dict[@"maxWidth"] = @(options.maxWidth());
214
+ dict[@"maxHeight"] = @(options.maxHeight());
215
+
216
+ [VideoTrimSwift getFrameAt:url options:dict completion:^(NSDictionary<NSString *, id> * _Nonnull result) {
217
+ if (result[@"error"]) {
218
+ reject(@"ERR_FRAME_EXTRACTION", result[@"error"], [NSError errorWithDomain:@"" code:200 userInfo:nil]);
219
+ } else {
220
+ resolve(result);
221
+ }
222
+ }];
223
+ }
224
+
225
+ - (void)extractAudio:(nonnull NSString *)url
226
+ options:(JS::NativeVideoTrim::ExtractAudioOptions &)options
227
+ resolve:(nonnull RCTPromiseResolveBlock)resolve
228
+ reject:(nonnull RCTPromiseRejectBlock)reject {
229
+ NSMutableDictionary *dict = [NSMutableDictionary dictionary];
230
+ dict[@"outputExt"] = options.outputExt();
231
+
232
+ [VideoTrimSwift extractAudio:url options:dict completion:^(NSDictionary<NSString *, id> * _Nonnull result) {
233
+ if (result[@"error"]) {
234
+ reject(@"ERR_EXTRACT_AUDIO", result[@"error"], [NSError errorWithDomain:@"" code:200 userInfo:nil]);
235
+ } else {
236
+ resolve(result);
237
+ }
238
+ }];
239
+ }
240
+
241
+ - (void)compress:(nonnull NSString *)url
242
+ options:(JS::NativeVideoTrim::CompressOptions &)options
243
+ resolve:(nonnull RCTPromiseResolveBlock)resolve
244
+ reject:(nonnull RCTPromiseRejectBlock)reject {
245
+ NSMutableDictionary *dict = [NSMutableDictionary dictionary];
246
+ dict[@"quality"] = options.quality();
247
+ dict[@"bitrate"] = @(options.bitrate());
248
+ dict[@"width"] = @(options.width());
249
+ dict[@"height"] = @(options.height());
250
+ dict[@"frameRate"] = @(options.frameRate());
251
+ dict[@"outputExt"] = options.outputExt();
252
+ dict[@"removeAudio"] = @(options.removeAudio());
253
+
254
+ [VideoTrimSwift compress:url options:dict completion:^(NSDictionary<NSString *, id> * _Nonnull result) {
255
+ if (result[@"error"]) {
256
+ reject(@"ERR_COMPRESS", result[@"error"], [NSError errorWithDomain:@"" code:200 userInfo:nil]);
257
+ } else {
258
+ resolve(result);
259
+ }
260
+ }];
261
+ }
262
+
263
+ - (void)toGif:(nonnull NSString *)url
264
+ options:(JS::NativeVideoTrim::GifOptions &)options
265
+ resolve:(nonnull RCTPromiseResolveBlock)resolve
266
+ reject:(nonnull RCTPromiseRejectBlock)reject {
267
+ NSMutableDictionary *dict = [NSMutableDictionary dictionary];
268
+ dict[@"startTime"] = @(options.startTime());
269
+ dict[@"endTime"] = @(options.endTime());
270
+ dict[@"fps"] = @(options.fps());
271
+ dict[@"width"] = @(options.width());
272
+
273
+ [VideoTrimSwift toGif:url options:dict completion:^(NSDictionary<NSString *, id> * _Nonnull result) {
274
+ if (result[@"error"]) {
275
+ reject(@"ERR_GIF", result[@"error"], [NSError errorWithDomain:@"" code:200 userInfo:nil]);
276
+ } else {
277
+ resolve(result);
278
+ }
279
+ }];
280
+ }
281
+
282
+ - (void)merge:(nonnull NSArray<NSString *> *)urls
283
+ options:(JS::NativeVideoTrim::MergeOptions &)options
284
+ resolve:(nonnull RCTPromiseResolveBlock)resolve
285
+ reject:(nonnull RCTPromiseRejectBlock)reject {
286
+ NSMutableDictionary *dict = [NSMutableDictionary dictionary];
287
+ dict[@"outputExt"] = options.outputExt();
288
+
289
+ [VideoTrimSwift merge:urls options:dict completion:^(NSDictionary<NSString *, id> * _Nonnull result) {
290
+ if (result[@"error"]) {
291
+ reject(@"ERR_MERGE", result[@"error"], [NSError errorWithDomain:@"" code:200 userInfo:nil]);
292
+ } else {
293
+ resolve(result);
294
+ }
295
+ }];
296
+ }
297
+
298
+ - (void)saveToPhoto:(nonnull NSString *)filePath
299
+ resolve:(nonnull RCTPromiseResolveBlock)resolve
300
+ reject:(nonnull RCTPromiseRejectBlock)reject {
301
+ [VideoTrimSwift saveToPhoto:filePath completion:^(NSDictionary<NSString *, id> * _Nonnull result) {
302
+ if (result[@"error"]) {
303
+ reject(@"ERR_SAVE_TO_PHOTO", result[@"error"], [NSError errorWithDomain:@"" code:200 userInfo:nil]);
304
+ } else {
305
+ resolve(result);
306
+ }
307
+ }];
308
+ }
309
+
310
+ - (void)saveToDocuments:(nonnull NSString *)filePath
311
+ resolve:(nonnull RCTPromiseResolveBlock)resolve
312
+ reject:(nonnull RCTPromiseRejectBlock)reject {
313
+ [VideoTrimSwift saveToDocuments:filePath completion:^(NSDictionary<NSString *, id> * _Nonnull result) {
314
+ if (result[@"error"]) {
315
+ reject(@"ERR_SAVE_TO_DOCUMENTS", result[@"error"], [NSError errorWithDomain:@"" code:200 userInfo:nil]);
316
+ } else {
317
+ resolve(result);
318
+ }
319
+ }];
320
+ }
321
+
322
+ - (void)share:(nonnull NSString *)filePath
323
+ resolve:(nonnull RCTPromiseResolveBlock)resolve
324
+ reject:(nonnull RCTPromiseRejectBlock)reject {
325
+ [VideoTrimSwift share:filePath completion:^(NSDictionary<NSString *, id> * _Nonnull result) {
326
+ if (result[@"error"]) {
327
+ reject(@"ERR_SHARE", result[@"error"], [NSError errorWithDomain:@"" code:200 userInfo:nil]);
328
+ } else {
329
+ resolve(result);
330
+ }
331
+ }];
332
+ }
333
+
196
334
  - (void)closeEditor {
197
335
  if (self->videoTrim) {
198
336
  [self->videoTrim closeEditor:0];
@@ -253,6 +391,27 @@ RCT_EXTERN_METHOD(isValidFile:(NSString*)uri withResolver:(RCTPromiseResolveBloc
253
391
  RCT_EXTERN_METHOD(trim:(NSString*)uri withConfig:(NSDictionary *)config
254
392
  withResolver:(RCTPromiseResolveBlock)resolve
255
393
  withRejecter:(RCTPromiseRejectBlock)reject)
394
+ RCT_EXTERN_METHOD(getFrameAt:(NSString*)url withOptions:(NSDictionary *)options
395
+ withResolver:(RCTPromiseResolveBlock)resolve
396
+ withRejecter:(RCTPromiseRejectBlock)reject)
397
+ RCT_EXTERN_METHOD(extractAudio:(NSString*)url withOptions:(NSDictionary *)options
398
+ withResolver:(RCTPromiseResolveBlock)resolve
399
+ withRejecter:(RCTPromiseRejectBlock)reject)
400
+ RCT_EXTERN_METHOD(compress:(NSString*)url withOptions:(NSDictionary *)options
401
+ withResolver:(RCTPromiseResolveBlock)resolve
402
+ withRejecter:(RCTPromiseRejectBlock)reject)
403
+ RCT_EXTERN_METHOD(toGif:(NSString*)url withOptions:(NSDictionary *)options
404
+ withResolver:(RCTPromiseResolveBlock)resolve
405
+ withRejecter:(RCTPromiseRejectBlock)reject)
406
+ RCT_EXTERN_METHOD(merge:(NSArray *)urls withOptions:(NSDictionary *)options
407
+ withResolver:(RCTPromiseResolveBlock)resolve
408
+ withRejecter:(RCTPromiseRejectBlock)reject)
409
+ RCT_EXTERN_METHOD(saveToPhoto:(NSString*)filePath withResolver:(RCTPromiseResolveBlock)resolve
410
+ withRejecter:(RCTPromiseRejectBlock)reject)
411
+ RCT_EXTERN_METHOD(saveToDocuments:(NSString*)filePath withResolver:(RCTPromiseResolveBlock)resolve
412
+ withRejecter:(RCTPromiseRejectBlock)reject)
413
+ RCT_EXTERN_METHOD(share:(NSString*)filePath withResolver:(RCTPromiseResolveBlock)resolve
414
+ withRejecter:(RCTPromiseRejectBlock)reject)
256
415
  @end
257
416
 
258
417
  #endif