react-native-compressor 1.7.1 → 1.8.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.
- package/README.md +40 -15
- package/android/build.gradle +8 -0
- package/android/src/main/java/com/reactnativecompressor/Audio/AudioCompressor.kt +527 -0
- package/android/src/main/java/com/reactnativecompressor/Audio/AudioMain.kt +31 -0
- package/android/src/main/java/com/reactnativecompressor/CompressorModule.kt +157 -0
- package/android/src/main/java/com/reactnativecompressor/CompressorPackage.kt +34 -0
- package/android/src/main/java/com/reactnativecompressor/Image/ImageCompressor.kt +199 -0
- package/android/src/main/java/com/reactnativecompressor/Image/ImageCompressorOptions.kt +57 -0
- package/android/src/main/java/com/reactnativecompressor/Image/ImageMain.kt +31 -0
- package/android/src/main/java/com/reactnativecompressor/Image/ImageSize.kt +3 -0
- package/android/src/main/java/com/reactnativecompressor/Utils/Downloader.kt +119 -0
- package/android/src/main/java/com/reactnativecompressor/Utils/EventEmitterHandler.kt +66 -0
- package/android/src/main/java/com/reactnativecompressor/Utils/MediaCache.kt +61 -0
- package/android/src/main/java/com/reactnativecompressor/Utils/RealPathUtil.kt +177 -0
- package/android/src/main/java/com/reactnativecompressor/Utils/Uploader.kt +117 -0
- package/android/src/main/java/com/reactnativecompressor/Utils/Utils.kt +162 -0
- package/android/src/main/java/com/reactnativecompressor/Video/AutoVideoCompression.kt +63 -0
- package/android/src/main/java/com/reactnativecompressor/Video/VideoCompressorHelper.kt +125 -0
- package/android/src/main/java/com/reactnativecompressor/Video/VideoMain.kt +86 -0
- package/android/src/newarch/CompressorSpec.kt +5 -0
- package/android/src/oldarch/CompressorSpec.kt +32 -0
- package/ios/Audio/AudioMain.swift +115 -0
- package/ios/Compressor-Bridging-Header.h +1 -2
- package/ios/Compressor.h +0 -8
- package/ios/Compressor.mm +28 -389
- package/ios/CompressorManager.swift +96 -0
- package/ios/Image/ImageCompressor.swift +354 -0
- package/ios/Image/ImageCompressorOptions.swift +93 -0
- package/ios/Image/ImageMain.swift +27 -0
- package/ios/Utils/Downloader.swift +157 -0
- package/ios/Utils/EventEmitterHandler.swift +54 -0
- package/ios/Utils/MediaCache.swift +48 -0
- package/ios/Utils/Uploader.swift +99 -0
- package/ios/Utils/Utils.swift +110 -0
- package/ios/Video/{VideoCompressor.swift → VideoMain.swift} +168 -147
- package/lib/commonjs/Image/index.js +1 -1
- package/lib/commonjs/Image/index.js.map +1 -1
- package/lib/commonjs/Main.js +1 -8
- package/lib/commonjs/Main.js.map +1 -1
- package/lib/commonjs/Spec/NativeCompressor.js.map +1 -1
- package/lib/commonjs/Video/index.js +4 -33
- package/lib/commonjs/Video/index.js.map +1 -1
- package/lib/commonjs/expo-plugin/compressor.js.map +1 -1
- package/lib/commonjs/index.js +11 -6
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/Downloader.js +38 -0
- package/lib/commonjs/utils/Downloader.js.map +1 -0
- package/lib/commonjs/utils/Uploader.js +40 -0
- package/lib/commonjs/utils/Uploader.js.map +1 -0
- package/lib/commonjs/utils/index.js +35 -0
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/module/Image/index.js +1 -1
- package/lib/module/Image/index.js.map +1 -1
- package/lib/module/Main.js +1 -7
- package/lib/module/Main.js.map +1 -1
- package/lib/module/Spec/NativeCompressor.js.map +1 -1
- package/lib/module/Video/index.js +5 -33
- package/lib/module/Video/index.js.map +1 -1
- package/lib/module/expo-plugin/compressor.js.map +1 -1
- package/lib/module/index.js +6 -6
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/Downloader.js +31 -0
- package/lib/module/utils/Downloader.js.map +1 -0
- package/lib/module/utils/Uploader.js +33 -0
- package/lib/module/utils/Uploader.js.map +1 -0
- package/lib/module/utils/index.js +2 -0
- package/lib/module/utils/index.js.map +1 -1
- package/lib/typescript/Image/index.d.ts +4 -0
- package/lib/typescript/Image/index.d.ts.map +1 -1
- package/lib/typescript/Main.d.ts +1 -2
- package/lib/typescript/Main.d.ts.map +1 -1
- package/lib/typescript/Spec/NativeCompressor.d.ts +8 -2
- package/lib/typescript/Spec/NativeCompressor.d.ts.map +1 -1
- package/lib/typescript/Video/index.d.ts +4 -28
- package/lib/typescript/Video/index.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +5 -4
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/utils/Downloader.d.ts +2 -0
- package/lib/typescript/utils/Downloader.d.ts.map +1 -0
- package/lib/typescript/utils/Uploader.d.ts +28 -0
- package/lib/typescript/utils/Uploader.d.ts.map +1 -0
- package/lib/typescript/utils/index.d.ts +2 -1
- package/lib/typescript/utils/index.d.ts.map +1 -1
- package/package.json +6 -4
- package/src/Image/index.tsx +5 -1
- package/src/Main.tsx +1 -15
- package/src/Spec/NativeCompressor.ts +14 -2
- package/src/Video/index.tsx +11 -84
- package/src/expo-plugin/compressor.ts +1 -1
- package/src/index.tsx +6 -3
- package/src/utils/Downloader.tsx +38 -0
- package/src/utils/Uploader.tsx +78 -0
- package/src/utils/index.tsx +2 -0
- package/android/src/main/java/com/reactnativecompressor/Audio/AudioCompressor.java +0 -605
- package/android/src/main/java/com/reactnativecompressor/CompressorModule.java +0 -220
- package/android/src/main/java/com/reactnativecompressor/CompressorPackage.java +0 -58
- package/android/src/main/java/com/reactnativecompressor/Image/ImageCompressor.java +0 -257
- package/android/src/main/java/com/reactnativecompressor/Image/utils/ImageCompressorOptions.java +0 -69
- package/android/src/main/java/com/reactnativecompressor/Image/utils/ImageSize.java +0 -13
- package/android/src/main/java/com/reactnativecompressor/Utils/FileUplaoder/FileUploadHelper.java +0 -39
- package/android/src/main/java/com/reactnativecompressor/Utils/FileUplaoder/FileUploader.java +0 -129
- package/android/src/main/java/com/reactnativecompressor/Utils/MediaCache.java +0 -65
- package/android/src/main/java/com/reactnativecompressor/Utils/RealPathUtil.java +0 -210
- package/android/src/main/java/com/reactnativecompressor/Utils/Utils.java +0 -272
- package/android/src/main/java/com/reactnativecompressor/Video/AutoVideoCompression/AutoVideoCompression.java +0 -87
- package/android/src/main/java/com/reactnativecompressor/Video/VideoCompressorHelper.java +0 -182
- package/android/src/main/java/com/reactnativecompressor/Video/VideoModule.java +0 -112
- package/android/src/newarch/CompressorSpec.java +0 -9
- package/android/src/newarch/VideoCompressorSpec.java +0 -9
- package/android/src/oldarch/CompressorSpec.java +0 -34
- package/android/src/oldarch/VideoCompressorSpec.java +0 -26
- package/ios/Image/ImageCompressor.h +0 -22
- package/ios/Image/ImageCompressor.m +0 -540
- package/ios/Image/ImageCompressorOptions.h +0 -28
- package/ios/Image/ImageCompressorOptions.m +0 -97
- package/ios/Utils/Downloader.h +0 -16
- package/ios/Utils/Downloader.m +0 -150
- package/ios/Utils/MediaCache.h +0 -11
- package/ios/Utils/MediaCache.m +0 -51
- package/ios/Video/VideoCompressor.h +0 -5
- package/ios/Video/VideoCompressor.m +0 -1
- package/lib/commonjs/Spec/NativeVideoCompressor.js +0 -10
- package/lib/commonjs/Spec/NativeVideoCompressor.js.map +0 -1
- package/lib/module/Spec/NativeVideoCompressor.js +0 -3
- package/lib/module/Spec/NativeVideoCompressor.js.map +0 -1
- package/lib/typescript/Spec/NativeVideoCompressor.d.ts +0 -13
- package/lib/typescript/Spec/NativeVideoCompressor.d.ts.map +0 -1
- package/src/Spec/NativeVideoCompressor.ts +0 -14
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
package com.reactnativecompressor.Video.AutoVideoCompression;
|
|
2
|
-
|
|
3
|
-
import android.media.MediaMetadataRetriever;
|
|
4
|
-
import android.net.Uri;
|
|
5
|
-
|
|
6
|
-
import androidx.annotation.Nullable;
|
|
7
|
-
|
|
8
|
-
import com.facebook.react.bridge.Promise;
|
|
9
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
10
|
-
import com.facebook.react.bridge.ReactContext;
|
|
11
|
-
import com.facebook.react.bridge.WritableMap;
|
|
12
|
-
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
13
|
-
import com.reactnativecompressor.Video.VideoCompressorHelper;
|
|
14
|
-
import static com.reactnativecompressor.Utils.Utils.compressVideo;
|
|
15
|
-
|
|
16
|
-
import java.io.File;
|
|
17
|
-
|
|
18
|
-
import static com.reactnativecompressor.Utils.Utils.generateCacheFilePath;
|
|
19
|
-
|
|
20
|
-
public class AutoVideoCompression {
|
|
21
|
-
public static void createCompressionSettings(String fileUrl,VideoCompressorHelper options,Promise promise, ReactApplicationContext reactContext) {
|
|
22
|
-
float maxSize = options.maxSize;
|
|
23
|
-
float minimumFileSizeForCompress=options.minimumFileSizeForCompress;
|
|
24
|
-
try{
|
|
25
|
-
Uri uri= Uri.parse(fileUrl);
|
|
26
|
-
String srcPath = uri.getPath();
|
|
27
|
-
MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever();
|
|
28
|
-
metaRetriever.setDataSource(srcPath);
|
|
29
|
-
File file=new File(srcPath);
|
|
30
|
-
float sizeInBytes = file.length();
|
|
31
|
-
float sizeInMb = sizeInBytes / (1024 * 1024);
|
|
32
|
-
if(sizeInMb>minimumFileSizeForCompress)
|
|
33
|
-
{
|
|
34
|
-
String destinationPath = generateCacheFilePath("mp4", reactContext);
|
|
35
|
-
int actualHeight =Integer.parseInt(metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
|
|
36
|
-
int actualWidth = Integer.parseInt(metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
|
|
37
|
-
int bitrate = Integer.parseInt(metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE));
|
|
38
|
-
|
|
39
|
-
float scale = actualWidth > actualHeight ? maxSize / actualWidth : maxSize / actualHeight;
|
|
40
|
-
int resultWidth = Math.round(actualWidth * scale / 2) * 2;
|
|
41
|
-
int resultHeight = Math.round(actualHeight * scale / 2) * 2;
|
|
42
|
-
|
|
43
|
-
float videoBitRate = makeVideoBitrate(
|
|
44
|
-
actualHeight, actualWidth,
|
|
45
|
-
bitrate,
|
|
46
|
-
resultHeight, resultWidth
|
|
47
|
-
);
|
|
48
|
-
compressVideo(srcPath, destinationPath, resultWidth, resultHeight, videoBitRate,options.uuid,promise,reactContext);
|
|
49
|
-
}
|
|
50
|
-
else
|
|
51
|
-
{
|
|
52
|
-
promise.resolve(fileUrl);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
} catch (Exception ex) {
|
|
56
|
-
promise.reject(ex);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
public static int makeVideoBitrate(int originalHeight, int originalWidth, int originalBitrate, int height, int width) {
|
|
61
|
-
float compressFactor = 0.8f;
|
|
62
|
-
float minCompressFactor = 0.8f;
|
|
63
|
-
int maxBitrate = 1669_000;
|
|
64
|
-
|
|
65
|
-
int remeasuredBitrate = (int) (originalBitrate / (Math.min(originalHeight / (float) (height), originalWidth / (float) (width))));
|
|
66
|
-
remeasuredBitrate *= compressFactor;
|
|
67
|
-
int minBitrate = (int) (getVideoBitrateWithFactor(minCompressFactor) / (1280f * 720f / (width * height)));
|
|
68
|
-
if (originalBitrate < minBitrate) {
|
|
69
|
-
return remeasuredBitrate;
|
|
70
|
-
}
|
|
71
|
-
if (remeasuredBitrate > maxBitrate) {
|
|
72
|
-
return maxBitrate;
|
|
73
|
-
}
|
|
74
|
-
return Math.max(remeasuredBitrate, minBitrate);
|
|
75
|
-
}
|
|
76
|
-
private static int getVideoBitrateWithFactor(float f) {
|
|
77
|
-
return (int) (f * 2000f * 1000f * 1.13f);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
private static void sendEvent(ReactContext reactContext,
|
|
81
|
-
String eventName,
|
|
82
|
-
@Nullable WritableMap params) {
|
|
83
|
-
reactContext
|
|
84
|
-
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
85
|
-
.emit(eventName, params);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
package com.reactnativecompressor.Video;
|
|
2
|
-
|
|
3
|
-
import android.annotation.SuppressLint;
|
|
4
|
-
import android.media.MediaMetadataRetriever;
|
|
5
|
-
import android.net.Uri;
|
|
6
|
-
import android.os.Handler;
|
|
7
|
-
import android.os.PowerManager;
|
|
8
|
-
|
|
9
|
-
import androidx.annotation.Nullable;
|
|
10
|
-
|
|
11
|
-
import com.facebook.react.bridge.LifecycleEventListener;
|
|
12
|
-
import com.facebook.react.bridge.Promise;
|
|
13
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
14
|
-
import com.facebook.react.bridge.ReactContext;
|
|
15
|
-
import com.facebook.react.bridge.ReadableMap;
|
|
16
|
-
import com.facebook.react.bridge.ReadableMapKeySetIterator;
|
|
17
|
-
import com.facebook.react.bridge.WritableMap;
|
|
18
|
-
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
19
|
-
import com.reactnativecompressor.Utils.FileUplaoder.FileUploader;
|
|
20
|
-
import com.reactnativecompressor.Video.AutoVideoCompression.AutoVideoCompression;
|
|
21
|
-
|
|
22
|
-
import java.util.UUID;
|
|
23
|
-
|
|
24
|
-
import static com.reactnativecompressor.Utils.Utils.compressVideo;
|
|
25
|
-
import static com.reactnativecompressor.Utils.Utils.generateCacheFilePath;
|
|
26
|
-
|
|
27
|
-
public class VideoCompressorHelper {
|
|
28
|
-
private static ReactApplicationContext _reactContext;
|
|
29
|
-
private static String backgroundId;
|
|
30
|
-
private static Handler handler;
|
|
31
|
-
private static Runnable runnable;
|
|
32
|
-
private static PowerManager powerManager;
|
|
33
|
-
private static PowerManager.WakeLock wakeLock;
|
|
34
|
-
private final static LifecycleEventListener listener = new LifecycleEventListener(){
|
|
35
|
-
@Override
|
|
36
|
-
public void onHostResume() {}
|
|
37
|
-
|
|
38
|
-
@Override
|
|
39
|
-
public void onHostPause() {}
|
|
40
|
-
|
|
41
|
-
@Override
|
|
42
|
-
public void onHostDestroy() {
|
|
43
|
-
if (wakeLock.isHeld()) {
|
|
44
|
-
wakeLock.release();
|
|
45
|
-
sendEventString(_reactContext, "backgroundTaskExpired", backgroundId);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
private static void sendEventString(ReactContext reactContext,
|
|
51
|
-
String eventName,
|
|
52
|
-
@Nullable String params) {
|
|
53
|
-
reactContext
|
|
54
|
-
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
55
|
-
.emit(eventName, params);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public static void video_upload_helper(String fileUrl, ReadableMap options, ReactApplicationContext reactContext, Promise promise) {
|
|
59
|
-
FileUploader.upload(fileUrl,options,reactContext,promise);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
@SuppressLint("InvalidWakeLockTag")
|
|
63
|
-
public static String video_activateBackgroundTask_helper(ReadableMap options, ReactApplicationContext reactContext) {
|
|
64
|
-
_reactContext=reactContext;
|
|
65
|
-
backgroundId= UUID.randomUUID().toString();
|
|
66
|
-
powerManager = (PowerManager) reactContext.getSystemService(reactContext.POWER_SERVICE);
|
|
67
|
-
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "bg_wakelock");
|
|
68
|
-
reactContext.addLifecycleEventListener(listener);
|
|
69
|
-
if (!wakeLock.isHeld()) {
|
|
70
|
-
wakeLock.acquire();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
handler = new Handler();
|
|
74
|
-
runnable = new Runnable() {
|
|
75
|
-
@Override
|
|
76
|
-
public void run() {
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
handler.post(runnable);
|
|
82
|
-
return "";
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
public static String video_deactivateBackgroundTask_helper(ReadableMap options,ReactApplicationContext reactContext) {
|
|
86
|
-
|
|
87
|
-
if (wakeLock.isHeld()) wakeLock.release();
|
|
88
|
-
|
|
89
|
-
// avoid null pointer exceptio when stop is called without start
|
|
90
|
-
if (handler != null) handler.removeCallbacks(runnable);
|
|
91
|
-
backgroundId="";
|
|
92
|
-
|
|
93
|
-
return "";
|
|
94
|
-
}
|
|
95
|
-
public enum CompressionMethod {
|
|
96
|
-
auto, manual
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
public VideoCompressorHelper.CompressionMethod compressionMethod = VideoCompressorHelper.CompressionMethod.auto;
|
|
100
|
-
public float bitrate = 0;
|
|
101
|
-
public String uuid = "";
|
|
102
|
-
public float maxSize = 640.0f;
|
|
103
|
-
public float minimumFileSizeForCompress = 0.0f;
|
|
104
|
-
|
|
105
|
-
public static VideoCompressorHelper fromMap(ReadableMap map) {
|
|
106
|
-
final VideoCompressorHelper options = new VideoCompressorHelper();
|
|
107
|
-
final ReadableMapKeySetIterator iterator = map.keySetIterator();
|
|
108
|
-
|
|
109
|
-
while (iterator.hasNextKey()) {
|
|
110
|
-
final String key = iterator.nextKey();
|
|
111
|
-
|
|
112
|
-
switch (key) {
|
|
113
|
-
case "compressionMethod":
|
|
114
|
-
options.compressionMethod = VideoCompressorHelper.CompressionMethod.valueOf(map.getString(key));
|
|
115
|
-
break;
|
|
116
|
-
case "maxSize":
|
|
117
|
-
options.maxSize = (float) map.getDouble(key);
|
|
118
|
-
break;
|
|
119
|
-
case "uuid":
|
|
120
|
-
options.uuid = map.getString(key);
|
|
121
|
-
break;
|
|
122
|
-
case "minimumFileSizeForCompress":
|
|
123
|
-
options.minimumFileSizeForCompress =(float) map.getDouble(key);
|
|
124
|
-
break;
|
|
125
|
-
case "bitrate":
|
|
126
|
-
options.bitrate = (float) map.getDouble(key);
|
|
127
|
-
break;
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return options;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
private static void sendEvent(ReactContext reactContext,
|
|
135
|
-
String eventName,
|
|
136
|
-
@Nullable WritableMap params) {
|
|
137
|
-
reactContext
|
|
138
|
-
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
139
|
-
.emit(eventName, params);
|
|
140
|
-
}
|
|
141
|
-
static int videoCompressionThreshold=10;
|
|
142
|
-
static int currentVideoCompression=0;
|
|
143
|
-
public static void VideoCompressManual(String fileUrl,VideoCompressorHelper options,Promise promise, ReactApplicationContext reactContext) {
|
|
144
|
-
try{
|
|
145
|
-
Uri uri= Uri.parse(fileUrl);
|
|
146
|
-
String srcPath = uri.getPath();
|
|
147
|
-
String destinationPath = generateCacheFilePath("mp4", reactContext);
|
|
148
|
-
MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever();
|
|
149
|
-
metaRetriever.setDataSource(srcPath);
|
|
150
|
-
int height =Integer.parseInt(metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
|
|
151
|
-
int width = Integer.parseInt(metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
|
|
152
|
-
int bitrate=Integer.parseInt(metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE));
|
|
153
|
-
|
|
154
|
-
boolean isPortrait = height > width;
|
|
155
|
-
int maxSize = (int) options.maxSize;
|
|
156
|
-
if(isPortrait && height > maxSize){
|
|
157
|
-
width = (int) (((float)maxSize/height)*width);
|
|
158
|
-
height = maxSize;
|
|
159
|
-
}else if(width > maxSize){
|
|
160
|
-
height = (int) (((float)maxSize/width)*height);
|
|
161
|
-
width = maxSize;
|
|
162
|
-
}
|
|
163
|
-
else
|
|
164
|
-
{
|
|
165
|
-
if(options.bitrate==0) {
|
|
166
|
-
options.bitrate = (int) (bitrate * 0.8);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
float videoBitRate = (options.bitrate>0)?options.bitrate: (float) (height * width * 1.5);
|
|
170
|
-
compressVideo(srcPath, destinationPath, width, height, videoBitRate,options.uuid,promise,reactContext);
|
|
171
|
-
} catch (Exception ex) {
|
|
172
|
-
promise.reject(ex);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
public static void VideoCompressAuto(String fileUrl,VideoCompressorHelper options,Promise promise, ReactApplicationContext reactContext) {
|
|
178
|
-
AutoVideoCompression.createCompressionSettings(fileUrl,options,promise,reactContext);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
package com.reactnativecompressor.Video;
|
|
2
|
-
|
|
3
|
-
import android.net.Uri;
|
|
4
|
-
import android.util.Log;
|
|
5
|
-
|
|
6
|
-
import androidx.annotation.NonNull;
|
|
7
|
-
import androidx.annotation.Nullable;
|
|
8
|
-
|
|
9
|
-
import com.facebook.react.bridge.Promise;
|
|
10
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
11
|
-
import com.facebook.react.bridge.ReactMethod;
|
|
12
|
-
import com.facebook.react.bridge.ReadableMap;
|
|
13
|
-
import com.reactnativecompressor.Utils.MediaCache;
|
|
14
|
-
import com.reactnativecompressor.VideoCompressorSpec;
|
|
15
|
-
import com.reactnativecompressor.Utils.RealPathUtil;
|
|
16
|
-
|
|
17
|
-
import static com.reactnativecompressor.Utils.Utils.getRealPath;
|
|
18
|
-
import static com.reactnativecompressor.Video.VideoCompressorHelper.video_activateBackgroundTask_helper;
|
|
19
|
-
import static com.reactnativecompressor.Video.VideoCompressorHelper.video_deactivateBackgroundTask_helper;
|
|
20
|
-
import static com.reactnativecompressor.Video.VideoCompressorHelper.video_upload_helper;
|
|
21
|
-
import static com.reactnativecompressor.Utils.Utils.cancelCompressionHelper;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
public class VideoModule extends VideoCompressorSpec {
|
|
25
|
-
public static final String NAME = "VideoCompressor";
|
|
26
|
-
private static final String TAG = "react-native-compessor";
|
|
27
|
-
private final ReactApplicationContext reactContext;
|
|
28
|
-
|
|
29
|
-
public VideoModule(ReactApplicationContext context) {
|
|
30
|
-
super(context);
|
|
31
|
-
this.reactContext = context;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
@NonNull
|
|
35
|
-
@Override
|
|
36
|
-
public String getName() {
|
|
37
|
-
return NAME;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
//Video
|
|
41
|
-
@ReactMethod
|
|
42
|
-
public void compress(
|
|
43
|
-
String fileUrl,
|
|
44
|
-
ReadableMap optionMap,
|
|
45
|
-
Promise promise) {
|
|
46
|
-
final VideoCompressorHelper options = VideoCompressorHelper.fromMap(optionMap);
|
|
47
|
-
|
|
48
|
-
fileUrl=getRealPath(fileUrl,reactContext,options.uuid);
|
|
49
|
-
|
|
50
|
-
if(options.compressionMethod==VideoCompressorHelper.CompressionMethod.auto)
|
|
51
|
-
{
|
|
52
|
-
VideoCompressorHelper.VideoCompressAuto(fileUrl,options,promise,reactContext);
|
|
53
|
-
}
|
|
54
|
-
else
|
|
55
|
-
{
|
|
56
|
-
VideoCompressorHelper.VideoCompressManual(fileUrl,options,promise,reactContext);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
@ReactMethod
|
|
61
|
-
public void cancelCompression(
|
|
62
|
-
String uuid) {
|
|
63
|
-
cancelCompressionHelper(uuid);
|
|
64
|
-
Log.d("cancelCompression", uuid);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
@ReactMethod
|
|
68
|
-
public void upload(
|
|
69
|
-
String fileUrl,
|
|
70
|
-
ReadableMap options,
|
|
71
|
-
Promise promise) {
|
|
72
|
-
try {
|
|
73
|
-
video_upload_helper(fileUrl,options,reactContext,promise);
|
|
74
|
-
} catch (Exception ex) {
|
|
75
|
-
promise.reject(ex);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
@ReactMethod
|
|
80
|
-
public void activateBackgroundTask(
|
|
81
|
-
ReadableMap options,
|
|
82
|
-
Promise promise) {
|
|
83
|
-
try {
|
|
84
|
-
String response=video_activateBackgroundTask_helper(options,reactContext);
|
|
85
|
-
promise.resolve(response);
|
|
86
|
-
} catch (Exception ex) {
|
|
87
|
-
promise.reject(ex);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
@ReactMethod
|
|
92
|
-
public void deactivateBackgroundTask(
|
|
93
|
-
ReadableMap options,
|
|
94
|
-
Promise promise) {
|
|
95
|
-
try {
|
|
96
|
-
String response=video_deactivateBackgroundTask_helper(options,reactContext);
|
|
97
|
-
promise.resolve(response);
|
|
98
|
-
} catch (Exception ex) {
|
|
99
|
-
promise.reject(ex);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
@ReactMethod
|
|
104
|
-
public void addListener(String eventName) {
|
|
105
|
-
// Keep: Required for RN built in Event Emitter Calls.
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
@ReactMethod
|
|
109
|
-
public void removeListeners(double count) {
|
|
110
|
-
// Keep: Required for RN built in Event Emitter Calls.
|
|
111
|
-
}
|
|
112
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
package com.reactnativecompressor;
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
4
|
-
|
|
5
|
-
public abstract class VideoCompressorSpec extends NativeVideoCompressorSpec {
|
|
6
|
-
protected VideoCompressorSpec(ReactApplicationContext context) {
|
|
7
|
-
super(context);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
package com.reactnativecompressor;
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
4
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
5
|
-
import com.facebook.react.bridge.Promise;
|
|
6
|
-
import com.facebook.react.bridge.ReadableMap;
|
|
7
|
-
|
|
8
|
-
abstract class CompressorSpec extends ReactContextBaseJavaModule {
|
|
9
|
-
CompressorSpec(ReactApplicationContext context) {
|
|
10
|
-
super(context);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
public abstract void image_compress(
|
|
14
|
-
String imagePath,
|
|
15
|
-
ReadableMap optionMap,
|
|
16
|
-
Promise promise);
|
|
17
|
-
|
|
18
|
-
public abstract void compress_audio(
|
|
19
|
-
String fileUrl,
|
|
20
|
-
ReadableMap optionMap,
|
|
21
|
-
Promise promise);
|
|
22
|
-
|
|
23
|
-
public abstract void generateFilePath(String extension, Promise promise);
|
|
24
|
-
|
|
25
|
-
public abstract void getRealPath(String path, String type, Promise promise);
|
|
26
|
-
|
|
27
|
-
public abstract void getVideoMetaData(String filePath, Promise promise);
|
|
28
|
-
|
|
29
|
-
public abstract void getFileSize(String filePath, Promise promise);
|
|
30
|
-
|
|
31
|
-
public abstract void addListener(String eventName);
|
|
32
|
-
|
|
33
|
-
public abstract void removeListeners(double count);
|
|
34
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
package com.reactnativecompressor;
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
4
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
5
|
-
import com.facebook.react.bridge.Promise;
|
|
6
|
-
import com.facebook.react.bridge.ReadableMap;
|
|
7
|
-
|
|
8
|
-
public abstract class VideoCompressorSpec extends ReactContextBaseJavaModule {
|
|
9
|
-
public VideoCompressorSpec(ReactApplicationContext context) {
|
|
10
|
-
super(context);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
public abstract void compress(String fileUrl, ReadableMap optionMap, Promise promise);
|
|
14
|
-
|
|
15
|
-
public abstract void cancelCompression(String uuid);
|
|
16
|
-
|
|
17
|
-
public abstract void upload(String fileUrl, ReadableMap options, Promise promise);
|
|
18
|
-
|
|
19
|
-
public abstract void activateBackgroundTask(ReadableMap options, Promise promise);
|
|
20
|
-
|
|
21
|
-
public abstract void deactivateBackgroundTask(ReadableMap options, Promise promise);
|
|
22
|
-
|
|
23
|
-
public abstract void addListener(String eventName);
|
|
24
|
-
|
|
25
|
-
public abstract void removeListeners(double count);
|
|
26
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
#import <UIKit/UIKit.h>
|
|
2
|
-
#import <React/RCTEventEmitter.h>
|
|
3
|
-
#import "Compressor.h"
|
|
4
|
-
#import "ImageCompressorOptions.h"
|
|
5
|
-
|
|
6
|
-
@interface ImageCompressor : RCTEventEmitter<NSObject>
|
|
7
|
-
+ (UIImage *)decodeImage:(NSString *)base64;
|
|
8
|
-
+ (UIImage *)loadImage:(NSString *)path;
|
|
9
|
-
+ (NSString *)generateCacheFilePath:(NSString *)extension;
|
|
10
|
-
|
|
11
|
-
+ (UIImage *)manualResize:(UIImage *)image maxWidth:(int)maxWidth maxHeight:(int)maxHeight;
|
|
12
|
-
+ (NSString *)manualCompressHandler:(NSString *)imagePath options:(ImageCompressorOptions *)options;
|
|
13
|
-
+ (NSString *)autoCompressHandler:(NSString *)imagePath options:(ImageCompressorOptions *)options;
|
|
14
|
-
+ (NSString *)manualCompress:(UIImage *)image output:(enum OutputType)output quality:(float)quality outputExtension:(NSString *)outputExtension isBase64:(Boolean)isBase64;
|
|
15
|
-
+ (UIImage *)scaleAndRotateImage:(UIImage *)image;
|
|
16
|
-
+ (void)getAbsoluteImagePath:(NSString *)imagePath uuid:(NSString *)uuid completionHandler:(void (^)(NSString *absoluteImagePath))completionHandler;
|
|
17
|
-
+ (void)getAbsoluteVideoPath:(NSString *)videoPath uuid:(NSString *)uuid completionHandler:(void (^)(NSString *absoluteImagePath))completionHandler;
|
|
18
|
-
+ (void)downloadFileAndSaveToCache:(NSString *)fileUrl;
|
|
19
|
-
+ (void)getFileSizeFromURL:(NSString *)urlString completion:(void (^)(NSNumber *fileSize, NSError *error))completion;
|
|
20
|
-
+ (void)initCompressorInstance:(Compressor*)instance;
|
|
21
|
-
+ (void)initVideoCompressorInstance:(id)object;
|
|
22
|
-
@end
|