react-native-compressor 1.3.4 → 1.3.5-alpha

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.
@@ -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
Binary file
@@ -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,6 @@
1
1
  package com.reactnativecompressor.Video;
2
2
 
3
+ import android.net.Uri;
3
4
  import android.util.Log;
4
5
 
5
6
  import androidx.annotation.NonNull;
@@ -14,14 +15,17 @@ import com.facebook.react.bridge.ReadableMap;
14
15
  import com.facebook.react.bridge.WritableMap;
15
16
  import com.facebook.react.module.annotations.ReactModule;
16
17
  import com.facebook.react.modules.core.DeviceEventManagerModule;
18
+ import com.reactnativecompressor.Utils.RealPathUtil;
17
19
 
18
20
  import static com.reactnativecompressor.Video.VideoCompressorHelper.video_activateBackgroundTask_helper;
19
21
  import static com.reactnativecompressor.Video.VideoCompressorHelper.video_deactivateBackgroundTask_helper;
20
22
  import static com.reactnativecompressor.Video.VideoCompressorHelper.video_upload_helper;
21
23
  import static com.reactnativecompressor.Utils.Utils.cancelCompressionHelper;
24
+
22
25
  @ReactModule(name = VideoModule.NAME)
23
26
  public class VideoModule extends ReactContextBaseJavaModule {
24
27
  public static final String NAME = "VideoCompressor";
28
+ private static final String TAG = "react-native-compessor";
25
29
  private final ReactApplicationContext reactContext;
26
30
  public VideoModule(ReactApplicationContext reactContext) {
27
31
  super(reactContext);
@@ -50,6 +54,17 @@ public class VideoModule extends ReactContextBaseJavaModule {
50
54
  Promise promise) {
51
55
  final VideoCompressorHelper options = VideoCompressorHelper.fromMap(optionMap);
52
56
 
57
+ if(fileUrl.startsWith("content://"))
58
+ {
59
+ try {
60
+ Uri uri= Uri.parse(fileUrl);
61
+ fileUrl= RealPathUtil.getRealPath(reactContext,uri);
62
+ }
63
+ catch (Exception ex) {
64
+ Log.d(TAG, " Please see this issue: https://github.com/Shobbak/react-native-compressor/issues/25");
65
+ }
66
+ }
67
+
53
68
  if(options.compressionMethod==VideoCompressorHelper.CompressionMethod.auto)
54
69
  {
55
70
  VideoCompressorHelper.VideoCompressAuto(fileUrl,options,promise,reactContext);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-compressor",
3
- "version": "1.3.4",
3
+ "version": "1.3.5-alpha",
4
4
  "description": "This library compress image, video and audio",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",