react-native-compressor 0.5.12 → 0.5.17

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.
Files changed (45) hide show
  1. package/README.md +74 -1
  2. package/android/.gradle/6.1.1/fileHashes/fileHashes.lock +0 -0
  3. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  4. package/android/.gradle/buildOutputCleanup/cache.properties +2 -2
  5. package/android/.gradle/checksums/checksums.lock +0 -0
  6. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  7. package/android/build.gradle +40 -44
  8. package/android/src/main/java/com/.DS_Store +0 -0
  9. package/android/src/main/java/com/reactnativecompressor/.DS_Store +0 -0
  10. package/android/src/main/java/com/reactnativecompressor/Audio/AudioCompressor.java +0 -6
  11. package/android/src/main/java/com/reactnativecompressor/CompressorModule.java +46 -37
  12. package/android/src/main/java/com/reactnativecompressor/Utils/RealPathUtil.java +210 -0
  13. package/android/src/main/java/com/reactnativecompressor/Utils/Utils.java +32 -1
  14. package/android/src/main/java/com/reactnativecompressor/Video/AutoVideoCompression/AutoVideoCompression.java +24 -58
  15. package/android/src/main/java/com/reactnativecompressor/Video/VideoCompressorHelper.java +6 -42
  16. package/android/src/main/java/com/reactnativecompressor/Video/VideoModule.java +23 -15
  17. package/ios/.DS_Store +0 -0
  18. package/ios/Compressor-Bridging-Header.h +1 -1
  19. package/ios/Compressor.m +120 -12
  20. package/ios/Image/ImageCompressor.h +2 -0
  21. package/ios/Image/ImageCompressor.m +153 -1
  22. package/ios/Video/VideoCompressor.swift +56 -59
  23. package/lib/commonjs/Audio/index.js.map +1 -1
  24. package/lib/commonjs/Video/index.js +46 -31
  25. package/lib/commonjs/Video/index.js.map +1 -1
  26. package/lib/commonjs/index.js +22 -1
  27. package/lib/commonjs/index.js.map +1 -1
  28. package/lib/commonjs/utils/index.js +18 -4
  29. package/lib/commonjs/utils/index.js.map +1 -1
  30. package/lib/module/Audio/index.js.map +1 -1
  31. package/lib/module/Video/index.js +39 -30
  32. package/lib/module/Video/index.js.map +1 -1
  33. package/lib/module/index.js +6 -3
  34. package/lib/module/index.js.map +1 -1
  35. package/lib/module/utils/index.js +9 -4
  36. package/lib/module/utils/index.js.map +1 -1
  37. package/lib/typescript/Video/index.d.ts +4 -0
  38. package/lib/typescript/index.d.ts +5 -2
  39. package/lib/typescript/utils/index.d.ts +3 -0
  40. package/package.json +1 -1
  41. package/react-native-compressor.podspec +1 -1
  42. package/src/Audio/index.tsx +1 -1
  43. package/src/Video/index.tsx +49 -37
  44. package/src/index.tsx +13 -1
  45. package/src/utils/index.tsx +14 -3
package/README.md CHANGED
@@ -31,7 +31,7 @@
31
31
  #### For React Native<0.65
32
32
 
33
33
  ```sh
34
- yarn add react-native-compressor@0.5.9
34
+ yarn add react-native-compressor@0.5.15
35
35
  ```
36
36
 
37
37
  Using Npm
@@ -244,6 +244,79 @@ const result = await Audio.compress(
244
244
 
245
245
  **Note: Audio compression will be add soon**
246
246
 
247
+ ## Background Upload
248
+
249
+ - ###### `backgroundUpload: (url: string, fileUrl: string, options: FileSystemUploadOptions, onProgress?: ((writtem: number, total: number) => void) | undefined) => Promise<any>
250
+
251
+ - ###### ` FileSystemUploadOptions`
252
+
253
+ ```js
254
+ type FileSystemUploadOptions = (
255
+ | {
256
+ uploadType?: FileSystemUploadType.BINARY_CONTENT,
257
+ }
258
+ | {
259
+ uploadType: FileSystemUploadType.MULTIPART,
260
+ fieldName?: string,
261
+ mimeType?: string,
262
+ parameters?: Record<string, string>,
263
+ }
264
+ ) & {
265
+ headers?: Record<string, string>,
266
+ httpMethod?: FileSystemAcceptedUploadHttpMethod,
267
+ sessionType?: FileSystemSessionType,
268
+ };
269
+ ```
270
+
271
+ ### Get Metadata Of Video
272
+
273
+ if you want to get metadata of video than you can use this function
274
+
275
+ ```js
276
+ import { getVideoMetaData } from 'react-native-compressor';
277
+
278
+ const metaData = await getVideoMetaData(filePath);
279
+ ```
280
+
281
+ ```
282
+ {
283
+ "duration": "6",
284
+ "extension": "mp4",
285
+ "height": "1080",
286
+ "size": "16940.0",
287
+ "width": "1920"
288
+ }
289
+ ```
290
+
291
+ - ###### `getVideoMetaData(path: string)`
292
+
293
+ ### Get Real Path
294
+
295
+ if you want to convert
296
+
297
+ - `content://` to `file:///` for android
298
+ - `ph://` to `file:///` for IOS
299
+
300
+ the you can you `getRealPath` function like this
301
+
302
+ ```js
303
+ import { getRealPath } from 'react-native-compressor';
304
+
305
+ const realPath = await getRealPath(fileUri, 'video'); // file://file_path.extension
306
+ ```
307
+
308
+ - ###### `getRealPath(path: string, type: string = 'video'|'image')`
309
+
310
+ ### Get Temp file Path
311
+
312
+ if you wanna make random file path in cache folder then you can use this method like this
313
+
314
+ ```js
315
+ import { getRealPath } from 'react-native-compressor';
316
+
317
+ const randomFilePathForSaveFile = await generateFilePath('mp4'); // file://file_path.mp4
318
+ ```
319
+
247
320
  ## Contributing
248
321
 
249
322
  See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
@@ -1,2 +1,2 @@
1
- #Tue Jan 04 23:36:59 PKT 2022
2
- gradle.version=6.1.1
1
+ #Thu Jan 27 18:54:59 PKT 2022
2
+ gradle.version=6.9
@@ -1,66 +1,62 @@
1
1
  buildscript {
2
- if (project == rootProject) {
3
- repositories {
4
- google()
5
- mavenCentral()
6
- }
2
+ if (project == rootProject) {
3
+ repositories {
4
+ google()
5
+ mavenCentral()
6
+ }
7
7
 
8
- dependencies {
9
- classpath 'com.android.tools.build:gradle:3.5.3'
10
- }
8
+ dependencies {
9
+ classpath 'com.android.tools.build:gradle:3.5.3'
11
10
  }
11
+ }
12
12
  }
13
13
 
14
14
  apply plugin: 'com.android.library'
15
15
 
16
16
  def safeExtGet(prop, fallback) {
17
- rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
17
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
18
18
  }
19
19
 
20
20
  android {
21
- compileSdkVersion safeExtGet('Compressor_compileSdkVersion', 29)
22
- buildToolsVersion safeExtGet('Compressor_buildToolsVersion', '29.0.2')
23
- defaultConfig {
24
- minSdkVersion safeExtGet('Compressor_minSdkVersion', 16)
25
- targetSdkVersion safeExtGet('Compressor_targetSdkVersion', 29)
26
- versionCode 1
27
- versionName "1.0"
28
-
29
- }
30
-
31
- buildTypes {
32
- release {
33
- minifyEnabled false
34
- }
35
- }
36
- lintOptions {
37
- disable 'GradleCompatible'
38
- }
39
- compileOptions {
40
- sourceCompatibility JavaVersion.VERSION_1_8
41
- targetCompatibility JavaVersion.VERSION_1_8
21
+ compileSdkVersion safeExtGet('Compressor_compileSdkVersion', 29)
22
+ buildToolsVersion safeExtGet('Compressor_buildToolsVersion', '29.0.2')
23
+ defaultConfig {
24
+ minSdkVersion safeExtGet('Compressor_minSdkVersion', 16)
25
+ targetSdkVersion safeExtGet('Compressor_targetSdkVersion', 29)
26
+ versionCode 1
27
+ versionName "1.0"
28
+
29
+ }
30
+
31
+ buildTypes {
32
+ release {
33
+ minifyEnabled false
42
34
  }
35
+ }
36
+ lintOptions {
37
+ disable 'GradleCompatible'
38
+ }
39
+ compileOptions {
40
+ sourceCompatibility JavaVersion.VERSION_1_8
41
+ targetCompatibility JavaVersion.VERSION_1_8
42
+ }
43
43
  }
44
44
 
45
45
  repositories {
46
- google()
47
- mavenLocal()
48
- maven {
49
- // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
50
- url("$rootDir/../node_modules/react-native/android")
51
- }
52
- mavenCentral()
53
- maven { url "https://www.jitpack.io" }
46
+ google()
47
+ mavenLocal()
48
+ maven {
49
+ // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
50
+ url("$rootDir/../node_modules/react-native/android")
51
+ }
52
+ mavenCentral()
53
+ maven { url "https://www.jitpack.io" }
54
54
  }
55
55
 
56
56
  dependencies {
57
- //noinspection GradleDynamicVersion
57
+ //noinspection GradleDynamicVersion
58
58
  implementation "com.facebook.react:react-native:+" // From node_modules
59
- implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.0"
60
- implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.0"
61
- implementation "com.googlecode.mp4parser:isoparser:1.0.6"
62
- implementation 'com.github.zolad:VideoSlimmer:master-SNAPSHOT'
63
59
  implementation 'io.github.lizhangqu:coreprogress:1.0.2'
64
- implementation 'com.github.nomi9995:VideoCompressor:43ec740572'
60
+ implementation 'com.github.nomi9995:VideoCompressor:715bcc16e9'
65
61
  // implementation project(path: ':videocompressor')
66
62
  }
Binary file
@@ -14,13 +14,7 @@ import android.os.Build;
14
14
 
15
15
  import androidx.annotation.RequiresApi;
16
16
 
17
- <<<<<<< HEAD
18
- import com.zolad.videoslimmer.VideoSlimmer;
19
- import com.zolad.videoslimmer.listner.SlimProgressListener;
20
- import com.zolad.videoslimmer.muxer.CodecInputSurface;
21
- =======
22
17
  import numan.dev.videocompressor.codecinputsurface.CodecInputSurface;
23
- >>>>>>> chore: add video compression cancel and fix stretch video
24
18
 
25
19
  import java.io.File;
26
20
  import java.io.IOException;
@@ -9,6 +9,7 @@ import androidx.annotation.NonNull;
9
9
  import androidx.annotation.Nullable;
10
10
  import androidx.annotation.RequiresApi;
11
11
 
12
+ import com.facebook.react.bridge.Arguments;
12
13
  import com.facebook.react.bridge.Promise;
13
14
  import com.facebook.react.bridge.ReactApplicationContext;
14
15
  import com.facebook.react.bridge.ReactContext;
@@ -20,15 +21,16 @@ import com.facebook.react.module.annotations.ReactModule;
20
21
  import com.facebook.react.modules.core.DeviceEventManagerModule;
21
22
  import com.reactnativecompressor.Image.ImageCompressor;
22
23
  import com.reactnativecompressor.Image.utils.ImageCompressorOptions;
24
+ import com.reactnativecompressor.Utils.Utils;
23
25
  import com.reactnativecompressor.Video.VideoCompressorHelper;
24
- <<<<<<< HEAD
25
- import com.zolad.videoslimmer.VideoSlimmer;
26
- =======
27
- >>>>>>> chore: add video compression cancel and fix stretch video
28
26
 
29
27
  import static com.reactnativecompressor.Utils.Utils.generateCacheFilePath;
28
+ import static com.reactnativecompressor.Utils.Utils.getRealPath;
29
+
30
30
  import com.reactnativecompressor.Audio.AudioCompressor;
31
31
 
32
+ import java.io.File;
33
+
32
34
  @ReactModule(name = CompressorModule.NAME)
33
35
  public class CompressorModule extends ReactContextBaseJavaModule {
34
36
  public static final String NAME = "Compressor";
@@ -59,6 +61,7 @@ public class CompressorModule extends ReactContextBaseJavaModule {
59
61
  ReadableMap optionMap,
60
62
  Promise promise) {
61
63
  try {
64
+ imagePath=Utils.getRealPath(imagePath,reactContext);
62
65
  final ImageCompressorOptions options = ImageCompressorOptions.fromMap(optionMap);
63
66
 
64
67
  if(options.compressionMethod==ImageCompressorOptions.CompressionMethod.auto)
@@ -93,39 +96,7 @@ public class CompressorModule extends ReactContextBaseJavaModule {
93
96
 
94
97
  float bitrate = options.bitrate;
95
98
  Log.d("nomi onStart", destinationPath+"onProgress: "+bitrate);
96
- <<<<<<< HEAD
97
- new AudioCompressor().CompressAudio(srcPath, destinationPath, (int) bitrate*1000, new VideoSlimmer.ProgressListener() {
98
-
99
-
100
- @Override
101
- public void onStart() {
102
- //convert start
103
- Log.d("nomi onStart", "onProgress: ");
104
-
105
- }
106
-
107
- @Override
108
- public void onFinish(boolean result) {
109
- //convert finish,result(true is success,false is fail)
110
- promise.resolve(destinationPath);
111
- Log.d("nomi onFinish", "onProgress: ");
112
- }
113
-
114
-
115
- @Override
116
- public void onProgress(float percent) {
117
- WritableMap params = Arguments.createMap();
118
- WritableMap data = Arguments.createMap();
119
- params.putString("uuid", options.uuid);
120
- data.putDouble("progress", percent/100);
121
- params.putMap("data", data);
122
- Log.d("nomi onProgress", "onProgress: "+percent);
123
- sendEvent(reactContext, "videoCompressProgress", params);
124
- }
125
- });
126
- =======
127
99
  new AudioCompressor().CompressAudio(srcPath, destinationPath, (int) bitrate*1000);
128
- >>>>>>> chore: add video compression cancel and fix stretch video
129
100
 
130
101
  } catch (Exception ex) {
131
102
  promise.reject(ex);
@@ -135,7 +106,7 @@ public class CompressorModule extends ReactContextBaseJavaModule {
135
106
 
136
107
  //General
137
108
  @ReactMethod
138
- public void generateFile(String extension, Promise promise) {
109
+ public void generateFilePath(String extension, Promise promise) {
139
110
  try {
140
111
  final String outputUri =generateCacheFilePath(extension,reactContext);
141
112
  promise.resolve(outputUri);
@@ -143,4 +114,42 @@ public class CompressorModule extends ReactContextBaseJavaModule {
143
114
  promise.reject(e);
144
115
  }
145
116
  }
117
+
118
+ @ReactMethod
119
+ public void getRealPath(String path,String type, Promise promise) {
120
+ try {
121
+ final String realPath =Utils.getRealPath(path,reactContext);
122
+ promise.resolve("file://"+realPath);
123
+ } catch (Exception e) {
124
+ promise.reject(e);
125
+ }
126
+ }
127
+
128
+ @ReactMethod
129
+ public void getVideoMetaData(String filePath, Promise promise) {
130
+ try {
131
+ filePath=Utils.getRealPath(filePath,reactContext);
132
+ Uri uri= Uri.parse(filePath);
133
+ String srcPath = uri.getPath();
134
+ MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever();
135
+ metaRetriever.setDataSource(srcPath);
136
+ File file=new File(srcPath);
137
+ float sizeInKBs = file.length()/1024;
138
+ int actualHeight =Integer.parseInt(metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
139
+ int actualWidth = Integer.parseInt(metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
140
+ long duration = Long.parseLong(metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
141
+ String extension = filePath.substring(filePath.lastIndexOf(".")+1);
142
+
143
+ WritableMap params = Arguments.createMap();
144
+ params.putString("size", String.valueOf(sizeInKBs));
145
+ params.putString("width", String.valueOf(actualWidth));
146
+ params.putString("height", String.valueOf(actualHeight));
147
+ params.putString("duration", String.valueOf(duration/1000));
148
+ params.putString("extension", extension);
149
+
150
+ promise.resolve(params);
151
+ } catch (Exception e) {
152
+ promise.reject(e);
153
+ }
154
+ }
146
155
  }
@@ -0,0 +1,210 @@
1
+ package com.reactnativecompressor.Utils;
2
+
3
+ import android.annotation.SuppressLint;
4
+ import android.content.ContentUris;
5
+ import android.content.Context;
6
+ import android.database.Cursor;
7
+ import android.net.Uri;
8
+ import android.os.Build;
9
+ import android.os.Environment;
10
+ import android.provider.DocumentsContract;
11
+ import android.provider.MediaStore;
12
+
13
+ import androidx.loader.content.CursorLoader;
14
+
15
+ public class RealPathUtil {
16
+
17
+ public static String getRealPath(Context context, Uri fileUri) {
18
+ String realPath;
19
+ // SDK < API11
20
+ if (Build.VERSION.SDK_INT < 11) {
21
+ realPath = RealPathUtil.getRealPathFromURI_BelowAPI11(context, fileUri);
22
+ }
23
+ // SDK >= 11 && SDK < 19
24
+ else if (Build.VERSION.SDK_INT < 19) {
25
+ realPath = RealPathUtil.getRealPathFromURI_API11to18(context, fileUri);
26
+ }
27
+ // SDK > 19 (Android 4.4) and up
28
+ else {
29
+ realPath = RealPathUtil.getRealPathFromURI_API19(context, fileUri);
30
+ }
31
+ return realPath;
32
+ }
33
+
34
+
35
+ @SuppressLint("NewApi")
36
+ public static String getRealPathFromURI_API11to18(Context context, Uri contentUri) {
37
+ String[] proj = {MediaStore.Images.Media.DATA};
38
+ String result = null;
39
+
40
+ CursorLoader cursorLoader = new CursorLoader(context, contentUri, proj, null, null, null);
41
+ Cursor cursor = cursorLoader.loadInBackground();
42
+
43
+ if (cursor != null) {
44
+ int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
45
+ cursor.moveToFirst();
46
+ result = cursor.getString(column_index);
47
+ cursor.close();
48
+ }
49
+ return result;
50
+ }
51
+
52
+ public static String getRealPathFromURI_BelowAPI11(Context context, Uri contentUri) {
53
+ String[] proj = {MediaStore.Images.Media.DATA};
54
+ Cursor cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
55
+ int column_index = 0;
56
+ String result = "";
57
+ if (cursor != null) {
58
+ column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
59
+ cursor.moveToFirst();
60
+ result = cursor.getString(column_index);
61
+ cursor.close();
62
+ return result;
63
+ }
64
+ return result;
65
+ }
66
+
67
+ /**
68
+ * Get a file path from a Uri. This will get the the path for Storage Access
69
+ * Framework Documents, as well as the _data field for the MediaStore and
70
+ * other file-based ContentProviders.
71
+ *
72
+ * @param context The context.
73
+ * @param uri The Uri to query.
74
+ * @author paulburke
75
+ */
76
+ @SuppressLint("NewApi")
77
+ public static String getRealPathFromURI_API19(final Context context, final Uri uri) {
78
+
79
+ final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
80
+
81
+ // DocumentProvider
82
+ if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
83
+ // ExternalStorageProvider
84
+ if (isExternalStorageDocument(uri)) {
85
+ final String docId = DocumentsContract.getDocumentId(uri);
86
+ final String[] split = docId.split(":");
87
+ final String type = split[0];
88
+
89
+ if ("primary".equalsIgnoreCase(type)) {
90
+ return Environment.getExternalStorageDirectory() + "/" + split[1];
91
+ }
92
+
93
+ // TODO handle non-primary volumes
94
+ }
95
+ // DownloadsProvider
96
+ else if (isDownloadsDocument(uri)) {
97
+
98
+ final String id = DocumentsContract.getDocumentId(uri);
99
+ final Uri contentUri = ContentUris.withAppendedId(
100
+ Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
101
+
102
+ return getDataColumn(context, contentUri, null, null);
103
+ }
104
+ // MediaProvider
105
+ else if (isMediaDocument(uri)) {
106
+ final String docId = DocumentsContract.getDocumentId(uri);
107
+ final String[] split = docId.split(":");
108
+ final String type = split[0];
109
+
110
+ Uri contentUri = null;
111
+ if ("image".equals(type)) {
112
+ contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
113
+ } else if ("video".equals(type)) {
114
+ contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
115
+ } else if ("audio".equals(type)) {
116
+ contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
117
+ }
118
+
119
+ final String selection = "_id=?";
120
+ final String[] selectionArgs = new String[]{
121
+ split[1]
122
+ };
123
+
124
+ return getDataColumn(context, contentUri, selection, selectionArgs);
125
+ }
126
+ }
127
+ // MediaStore (and general)
128
+ else if ("content".equalsIgnoreCase(uri.getScheme())) {
129
+
130
+ // Return the remote address
131
+ if (isGooglePhotosUri(uri))
132
+ return uri.getLastPathSegment();
133
+
134
+ return getDataColumn(context, uri, null, null);
135
+ }
136
+ // File
137
+ else if ("file".equalsIgnoreCase(uri.getScheme())) {
138
+ return uri.getPath();
139
+ }
140
+
141
+ return null;
142
+ }
143
+
144
+ /**
145
+ * Get the value of the data column for this Uri. This is useful for
146
+ * MediaStore Uris, and other file-based ContentProviders.
147
+ *
148
+ * @param context The context.
149
+ * @param uri The Uri to query.
150
+ * @param selection (Optional) Filter used in the query.
151
+ * @param selectionArgs (Optional) Selection arguments used in the query.
152
+ * @return The value of the _data column, which is typically a file path.
153
+ */
154
+ public static String getDataColumn(Context context, Uri uri, String selection,
155
+ String[] selectionArgs) {
156
+
157
+ Cursor cursor = null;
158
+ final String column = "_data";
159
+ final String[] projection = {
160
+ column
161
+ };
162
+
163
+ try {
164
+ cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
165
+ null);
166
+ if (cursor != null && cursor.moveToFirst()) {
167
+ final int index = cursor.getColumnIndexOrThrow(column);
168
+ return cursor.getString(index);
169
+ }
170
+ } finally {
171
+ if (cursor != null)
172
+ cursor.close();
173
+ }
174
+ return null;
175
+ }
176
+
177
+
178
+ /**
179
+ * @param uri The Uri to check.
180
+ * @return Whether the Uri authority is ExternalStorageProvider.
181
+ */
182
+ public static boolean isExternalStorageDocument(Uri uri) {
183
+ return "com.android.externalstorage.documents".equals(uri.getAuthority());
184
+ }
185
+
186
+ /**
187
+ * @param uri The Uri to check.
188
+ * @return Whether the Uri authority is DownloadsProvider.
189
+ */
190
+ public static boolean isDownloadsDocument(Uri uri) {
191
+ return "com.android.providers.downloads.documents".equals(uri.getAuthority());
192
+ }
193
+
194
+ /**
195
+ * @param uri The Uri to check.
196
+ * @return Whether the Uri authority is MediaProvider.
197
+ */
198
+ public static boolean isMediaDocument(Uri uri) {
199
+ return "com.android.providers.media.documents".equals(uri.getAuthority());
200
+ }
201
+
202
+ /**
203
+ * @param uri The Uri to check.
204
+ * @return Whether the Uri authority is Google Photos.
205
+ */
206
+ public static boolean isGooglePhotosUri(Uri uri) {
207
+ return "com.google.android.apps.photos.content".equals(uri.getAuthority());
208
+ }
209
+
210
+ }
@@ -1,5 +1,12 @@
1
1
  package com.reactnativecompressor.Utils;
2
2
 
3
+ import android.net.Uri;
4
+ import android.util.Log;
5
+
6
+ import androidx.annotation.Nullable;
7
+
8
+ import com.facebook.react.bridge.Arguments;
9
+ import com.facebook.react.bridge.Promise;
3
10
  import com.facebook.react.bridge.ReactApplicationContext;
4
11
  import com.facebook.react.bridge.ReactContext;
5
12
  import com.facebook.react.bridge.WritableMap;
@@ -8,10 +15,13 @@ import numan.dev.videocompressor.VideoCompressTask;
8
15
  import numan.dev.videocompressor.VideoCompressor;
9
16
 
10
17
  import java.io.File;
18
+ import java.util.HashMap;
19
+ import java.util.Map;
11
20
  import java.util.UUID;
12
21
 
13
22
  public class Utils {
14
23
  static int videoCompressionThreshold=10;
24
+ private static final String TAG = "react-native-compessor";
15
25
  static Map<String, VideoCompressTask> compressorExports = new HashMap<>();
16
26
 
17
27
  public static String generateCacheFilePath(String extension, ReactApplicationContext reactContext){
@@ -38,7 +48,14 @@ public class Utils {
38
48
 
39
49
  @Override
40
50
  public void onError(String errorMessage) {
41
- promise.reject("Compression has canncelled");
51
+ if(errorMessage.equals(("class java.lang.AssertionError")))
52
+ {
53
+ promise.resolve(srcPath);
54
+ }
55
+ else
56
+ {
57
+ promise.reject("Compression has canncelled");
58
+ }
42
59
  }
43
60
 
44
61
  @Override
@@ -80,4 +97,18 @@ public class Utils {
80
97
  .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
81
98
  .emit(eventName, params);
82
99
  }
100
+
101
+ public static String getRealPath(String fileUrl,ReactApplicationContext reactContext){
102
+ if(fileUrl.startsWith("content://"))
103
+ {
104
+ try {
105
+ Uri uri= Uri.parse(fileUrl);
106
+ fileUrl= RealPathUtil.getRealPath(reactContext,uri);
107
+ }
108
+ catch (Exception ex) {
109
+ Log.d(TAG, " Please see this issue: https://github.com/Shobbak/react-native-compressor/issues/25");
110
+ }
111
+ }
112
+ return fileUrl;
113
+ }
83
114
  }