react-native-compressor 1.18.0 → 1.18.1
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.
- package/ios/Video/VideoMain.swift +54 -54
- package/package.json +1 -1
|
@@ -347,18 +347,22 @@ class VideoCompressor {
|
|
|
347
347
|
}, completionHandler: { result in
|
|
348
348
|
currentVideoCompression=0;
|
|
349
349
|
self.compressorExports[uuid] = nil
|
|
350
|
-
switch
|
|
351
|
-
case .
|
|
352
|
-
|
|
350
|
+
switch result {
|
|
351
|
+
case .success:
|
|
352
|
+
if let outputURL = exporter.outputURL {
|
|
353
|
+
onCompletion(outputURL)
|
|
354
|
+
} else {
|
|
355
|
+
onFailure(CompressionError(message: "Compression succeeded but output URL is unavailable"))
|
|
356
|
+
}
|
|
353
357
|
break
|
|
354
|
-
case .
|
|
355
|
-
|
|
358
|
+
case .failure(let error):
|
|
359
|
+
if let nexterError = error as? NextLevelSessionExporterError, case .cancelled = nexterError {
|
|
360
|
+
onFailure(CompressionError(message: "Compression has cancelled"))
|
|
361
|
+
} else {
|
|
356
362
|
onFailure(error)
|
|
357
|
-
|
|
358
|
-
default:
|
|
359
|
-
onFailure(exporter.error ?? CompressionError(message: "Compression failed"))
|
|
363
|
+
}
|
|
360
364
|
break
|
|
361
|
-
|
|
365
|
+
}
|
|
362
366
|
})
|
|
363
367
|
}
|
|
364
368
|
|
|
@@ -373,58 +377,54 @@ class VideoCompressor {
|
|
|
373
377
|
|
|
374
378
|
|
|
375
379
|
func getVideoMetaData(_ filePath: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
if absoluteImagePath.hasPrefix("file://") {
|
|
379
|
-
|
|
380
|
-
let absoluteImagePath = URL(string: absoluteImagePath)!.path
|
|
381
|
-
let fileManager = FileManager.default
|
|
382
|
-
var isDir: ObjCBool = false
|
|
383
|
-
|
|
384
|
-
if !fileManager.fileExists(atPath: absoluteImagePath, isDirectory: &isDir) || isDir.boolValue {
|
|
385
|
-
let err = NSError(domain: "file not found", code: -15, userInfo: nil)
|
|
386
|
-
reject(String(err.code), err.localizedDescription, err)
|
|
387
|
-
return
|
|
388
|
-
}
|
|
380
|
+
VideoCompressor.getAbsoluteVideoPath(filePath, options: [:]) { absoluteImagePath in
|
|
381
|
+
if absoluteImagePath.hasPrefix("file://") {
|
|
389
382
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
var result: [String: Any] = [:]
|
|
395
|
-
let assetOptions: [String: Any] = [AVURLAssetPreferPreciseDurationAndTimingKey: true]
|
|
396
|
-
let asset = AVURLAsset(url: URL(fileURLWithPath: absoluteImagePath), options: assetOptions)
|
|
397
|
-
if let avAsset = asset.tracks(withMediaType: .video).first {
|
|
398
|
-
let size = avAsset.naturalSize
|
|
399
|
-
let _extension = (absoluteImagePath as NSString).pathExtension
|
|
400
|
-
let time = asset.duration
|
|
401
|
-
let seconds = Double(time.value) / Double(time.timescale)
|
|
402
|
-
|
|
403
|
-
result["width"] = size.width
|
|
404
|
-
result["height"] = size.height
|
|
405
|
-
result["extension"] = _extension
|
|
406
|
-
result["size"] = fileSizeString
|
|
407
|
-
result["duration"] = seconds
|
|
408
|
-
|
|
409
|
-
var commonMetadata: [AVMetadataItem] = []
|
|
410
|
-
for key in self.metadatas {
|
|
411
|
-
let items = AVMetadataItem.metadataItems(from: asset.commonMetadata, withKey: key, keySpace: AVMetadataKeySpace.common)
|
|
412
|
-
commonMetadata.append(contentsOf: items)
|
|
413
|
-
}
|
|
383
|
+
let absoluteImagePath = URL(string: absoluteImagePath)!.path
|
|
384
|
+
let fileManager = FileManager.default
|
|
385
|
+
var isDir: ObjCBool = false
|
|
414
386
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
387
|
+
if !fileManager.fileExists(atPath: absoluteImagePath, isDirectory: &isDir) || isDir.boolValue {
|
|
388
|
+
let err = NSError(domain: "file not found", code: -15, userInfo: nil)
|
|
389
|
+
reject(String(err.code), err.localizedDescription, err)
|
|
390
|
+
return
|
|
391
|
+
}
|
|
420
392
|
|
|
421
|
-
|
|
393
|
+
let attrs = try? fileManager.attributesOfItem(atPath: absoluteImagePath)
|
|
394
|
+
if let fileSize = attrs?[FileAttributeKey.size] as? UInt64 {
|
|
395
|
+
let fileSizeString = fileSize
|
|
396
|
+
|
|
397
|
+
var result: [String: Any] = [:]
|
|
398
|
+
let assetOptions: [String: Any] = [AVURLAssetPreferPreciseDurationAndTimingKey: true]
|
|
399
|
+
let asset = AVURLAsset(url: URL(fileURLWithPath: absoluteImagePath), options: assetOptions)
|
|
400
|
+
if let avAsset = asset.tracks(withMediaType: .video).first {
|
|
401
|
+
let size = avAsset.naturalSize
|
|
402
|
+
let _extension = (absoluteImagePath as NSString).pathExtension
|
|
403
|
+
let time = asset.duration
|
|
404
|
+
let seconds = Double(time.value) / Double(time.timescale)
|
|
405
|
+
|
|
406
|
+
result["width"] = size.width
|
|
407
|
+
result["height"] = size.height
|
|
408
|
+
result["extension"] = _extension
|
|
409
|
+
result["size"] = fileSizeString
|
|
410
|
+
result["duration"] = seconds
|
|
411
|
+
|
|
412
|
+
var commonMetadata: [AVMetadataItem] = []
|
|
413
|
+
for key in self.metadatas {
|
|
414
|
+
let items = AVMetadataItem.metadataItems(from: asset.commonMetadata, withKey: key, keySpace: AVMetadataKeySpace.common)
|
|
415
|
+
commonMetadata.append(contentsOf: items)
|
|
422
416
|
}
|
|
417
|
+
|
|
418
|
+
for item in commonMetadata {
|
|
419
|
+
if let value = item.value {
|
|
420
|
+
result[item.commonKey!.rawValue] = value
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
resolve(result)
|
|
423
425
|
}
|
|
424
426
|
}
|
|
425
427
|
}
|
|
426
|
-
} catch {
|
|
427
|
-
reject(error.localizedDescription, error.localizedDescription, nil)
|
|
428
428
|
}
|
|
429
429
|
}
|
|
430
430
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-compressor",
|
|
3
|
-
"version": "1.18.
|
|
3
|
+
"version": "1.18.1",
|
|
4
4
|
"description": "Compress Image, Video, and Audio same like Whatsapp & Auto/Manual Compression | Background Upload | Download File | Create Video Thumbnail",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|