react-native-compressor 1.6.3 → 1.7.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/LICENSE +1 -1
- package/README.md +15 -11
- package/android/build.gradle +95 -42
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +0 -1
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/reactnativecompressor/CompressorModule.java +88 -33
- package/android/src/main/java/com/reactnativecompressor/CompressorPackage.java +47 -19
- package/android/src/main/java/com/reactnativecompressor/Image/utils/ImageCompressorOptions.java +1 -1
- package/android/src/main/java/com/reactnativecompressor/Utils/Utils.java +1 -1
- package/android/src/main/java/com/reactnativecompressor/Video/VideoCompressorHelper.java +7 -4
- package/android/src/main/java/com/reactnativecompressor/Video/VideoModule.java +8 -6
- package/android/src/newarch/CompressorSpec.java +9 -0
- package/android/src/newarch/VideoCompressorSpec.java +9 -0
- package/android/src/oldarch/CompressorSpec.java +28 -0
- package/android/src/oldarch/VideoCompressorSpec.java +26 -0
- package/ios/Compressor.h +7 -0
- package/ios/Compressor.mm +395 -0
- package/ios/Compressor.xcodeproj/project.pbxproj +6 -36
- package/ios/Video/VideoCompressor.swift +2 -2
- package/lib/commonjs/Audio/index.js +13 -14
- package/lib/commonjs/Audio/index.js.map +1 -1
- package/lib/commonjs/Image/index.js +2 -5
- package/lib/commonjs/Image/index.js.map +1 -1
- package/lib/commonjs/Main.js +29 -0
- package/lib/commonjs/Main.js.map +1 -0
- package/lib/commonjs/Spec/NativeCompressor.js +10 -0
- package/lib/commonjs/Spec/NativeCompressor.js.map +1 -0
- package/lib/commonjs/Spec/NativeVideoCompressor.js +10 -0
- package/lib/commonjs/Spec/NativeVideoCompressor.js.map +1 -0
- package/lib/commonjs/Video/index.js +3 -24
- package/lib/commonjs/Video/index.js.map +1 -1
- package/lib/commonjs/expo-plugin/compressor.js +1 -4
- package/lib/commonjs/expo-plugin/compressor.js.map +1 -1
- package/lib/commonjs/index.js +21 -28
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/index.js +32 -51
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/module/Audio/index.js +13 -11
- package/lib/module/Audio/index.js.map +1 -1
- package/lib/module/Image/index.js +2 -3
- package/lib/module/Image/index.js.map +1 -1
- package/lib/module/Main.js +22 -0
- package/lib/module/Main.js.map +1 -0
- package/lib/module/Spec/NativeCompressor.js +3 -0
- package/lib/module/Spec/NativeCompressor.js.map +1 -0
- package/lib/module/Spec/NativeVideoCompressor.js +3 -0
- package/lib/module/Spec/NativeVideoCompressor.js.map +1 -0
- package/lib/module/Video/index.js +4 -18
- package/lib/module/Video/index.js.map +1 -1
- package/lib/module/expo-plugin/compressor.js +1 -3
- package/lib/module/expo-plugin/compressor.js.map +1 -1
- package/lib/module/index.js +8 -5
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/index.js +26 -34
- package/lib/module/utils/index.js.map +1 -1
- package/lib/typescript/Audio/index.d.ts +2 -1
- package/lib/typescript/Audio/index.d.ts.map +1 -0
- package/lib/typescript/Image/index.d.ts +7 -6
- package/lib/typescript/Image/index.d.ts.map +1 -0
- package/lib/typescript/Main.d.ts +4 -0
- package/lib/typescript/Main.d.ts.map +1 -0
- package/lib/typescript/Spec/NativeCompressor.d.ts +12 -0
- package/lib/typescript/Spec/NativeCompressor.d.ts.map +1 -0
- package/lib/typescript/Spec/NativeVideoCompressor.d.ts +13 -0
- package/lib/typescript/Spec/NativeVideoCompressor.d.ts.map +1 -0
- package/lib/typescript/Video/index.d.ts +4 -3
- package/lib/typescript/Video/index.d.ts.map +1 -0
- package/lib/typescript/expo-plugin/compressor.d.ts +2 -3
- package/lib/typescript/expo-plugin/compressor.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +7 -3
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/utils/index.d.ts +6 -4
- package/lib/typescript/utils/index.d.ts.map +1 -0
- package/package.json +59 -37
- package/react-native-compressor.podspec +24 -1
- package/src/Audio/index.tsx +6 -4
- package/src/Image/index.tsx +2 -2
- package/src/Main.tsx +41 -0
- package/src/Spec/NativeCompressor.ts +13 -0
- package/src/Spec/NativeVideoCompressor.ts +14 -0
- package/src/Video/index.tsx +5 -10
- package/src/expo-plugin/compressor.ts +2 -1
- package/src/index.tsx +7 -2
- package/src/utils/index.tsx +11 -5
- package/android/.gradle/6.9/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/6.9/fileChanges/last-build.bin +0 -0
- package/android/.gradle/6.9/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/6.9/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/6.9/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/.idea/caches/build_file_checksums.ser +0 -0
- package/android/.idea/compiler.xml +0 -6
- package/android/.idea/gradle.xml +0 -20
- package/android/.idea/jarRepositories.xml +0 -45
- package/android/.idea/libraries/Gradle__androidx_annotation_annotation_1_1_0.xml +0 -13
- package/android/.idea/libraries/Gradle__androidx_appcompat_appcompat_1_0_2_aar.xml +0 -24
- package/android/.idea/libraries/Gradle__androidx_arch_core_core_common_2_0_0.xml +0 -11
- package/android/.idea/libraries/Gradle__androidx_arch_core_core_runtime_2_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_asynclayoutinflater_asynclayoutinflater_1_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_autofill_autofill_1_1_0_aar.xml +0 -16
- package/android/.idea/libraries/Gradle__androidx_collection_collection_1_0_0.xml +0 -11
- package/android/.idea/libraries/Gradle__androidx_coordinatorlayout_coordinatorlayout_1_0_0_aar.xml +0 -24
- package/android/.idea/libraries/Gradle__androidx_core_core_1_1_0_aar.xml +0 -16
- package/android/.idea/libraries/Gradle__androidx_cursoradapter_cursoradapter_1_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_customview_customview_1_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_documentfile_documentfile_1_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_drawerlayout_drawerlayout_1_0_0_aar.xml +0 -24
- package/android/.idea/libraries/Gradle__androidx_fragment_fragment_1_0_0_aar.xml +0 -24
- package/android/.idea/libraries/Gradle__androidx_interpolator_interpolator_1_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_legacy_legacy_support_core_ui_1_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_legacy_legacy_support_core_utils_1_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_common_2_0_0.xml +0 -11
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_livedata_2_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_livedata_core_2_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_runtime_2_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_viewmodel_2_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_loader_loader_1_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_localbroadcastmanager_localbroadcastmanager_1_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_print_print_1_0_0_aar.xml +0 -24
- package/android/.idea/libraries/Gradle__androidx_slidingpanelayout_slidingpanelayout_1_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_swiperefreshlayout_swiperefreshlayout_1_0_0_aar.xml +0 -24
- package/android/.idea/libraries/Gradle__androidx_vectordrawable_vectordrawable_1_0_1_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_vectordrawable_vectordrawable_animated_1_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_versionedparcelable_versionedparcelable_1_1_0_aar.xml +0 -13
- package/android/.idea/libraries/Gradle__androidx_viewpager_viewpager_1_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__com_facebook_fbjni_fbjni_java_only_0_2_2.xml +0 -13
- package/android/.idea/libraries/Gradle__com_facebook_fresco_drawee_2_5_0_aar.xml +0 -15
- package/android/.idea/libraries/Gradle__com_facebook_fresco_fbcore_2_5_0_aar.xml +0 -18
- package/android/.idea/libraries/Gradle__com_facebook_fresco_fresco_2_5_0_aar.xml +0 -18
- package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_2_5_0_aar.xml +0 -18
- package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_base_2_5_0_aar.xml +0 -18
- package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_native_2_5_0_aar.xml +0 -15
- package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_okhttp3_2_5_0_aar.xml +0 -15
- package/android/.idea/libraries/Gradle__com_facebook_fresco_memory_type_ashmem_2_5_0_aar.xml +0 -15
- package/android/.idea/libraries/Gradle__com_facebook_fresco_memory_type_java_2_5_0_aar.xml +0 -15
- package/android/.idea/libraries/Gradle__com_facebook_fresco_memory_type_native_2_5_0_aar.xml +0 -15
- package/android/.idea/libraries/Gradle__com_facebook_fresco_nativeimagefilters_2_5_0_aar.xml +0 -15
- package/android/.idea/libraries/Gradle__com_facebook_fresco_nativeimagetranscoder_2_5_0_aar.xml +0 -15
- package/android/.idea/libraries/Gradle__com_facebook_fresco_ui_common_2_5_0_aar.xml +0 -15
- package/android/.idea/libraries/Gradle__com_facebook_infer_annotation_infer_annotation_0_18_0.xml +0 -13
- package/android/.idea/libraries/Gradle__com_facebook_react_react_native_0_66_1_aar.xml +0 -14
- package/android/.idea/libraries/Gradle__com_facebook_soloader_annotation_0_10_1.xml +0 -13
- package/android/.idea/libraries/Gradle__com_facebook_soloader_nativeloader_0_10_1.xml +0 -13
- package/android/.idea/libraries/Gradle__com_facebook_soloader_soloader_0_10_1_aar.xml +0 -15
- package/android/.idea/libraries/Gradle__com_facebook_yoga_proguard_annotations_1_19_0.xml +0 -13
- package/android/.idea/libraries/Gradle__com_google_code_findbugs_jsr305_3_0_2.xml +0 -13
- package/android/.idea/libraries/Gradle__com_googlecode_mp4parser_isoparser_1_0_6.xml +0 -13
- package/android/.idea/libraries/Gradle__com_squareup_okhttp3_okhttp_4_9_1.xml +0 -13
- package/android/.idea/libraries/Gradle__com_squareup_okhttp3_okhttp_urlconnection_4_9_1.xml +0 -13
- package/android/.idea/libraries/Gradle__com_squareup_okio_okio_2_9_0.xml +0 -13
- package/android/.idea/libraries/Gradle__io_github_lizhangqu_coreprogress_1_0_2_aar.xml +0 -18
- package/android/.idea/libraries/Gradle__javax_inject_javax_inject_1.xml +0 -13
- package/android/.idea/libraries/Gradle__org_aspectj_aspectjrt_1_8_2.xml +0 -13
- package/android/.idea/libraries/Gradle__org_jetbrains_annotations_13_0.xml +0 -13
- package/android/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_annotations_jvm_1_3_72.xml +0 -13
- package/android/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_4_10.xml +0 -13
- package/android/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_common_1_4_10.xml +0 -13
- package/android/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_jdk7_1_4_10.xml +0 -13
- package/android/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_jdk8_1_4_10.xml +0 -13
- package/android/.idea/libraries/Gradle__org_jetbrains_kotlinx_kotlinx_coroutines_android_1_4_0.xml +0 -13
- package/android/.idea/libraries/Gradle__org_jetbrains_kotlinx_kotlinx_coroutines_core_jvm_1_4_0.xml +0 -13
- package/android/.idea/misc.xml +0 -9
- package/android/.idea/modules/android.iml +0 -138
- package/android/.idea/modules.xml +0 -8
- package/android/.idea/vcs.xml +0 -6
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +0 -5
- package/android/gradlew +0 -183
- package/android/gradlew.bat +0 -100
- package/android/local.properties +0 -8
- package/ios/Compressor.m +0 -351
- package/ios/Compressor.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/Compressor.xcodeproj/project.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/Compressor.xcodeproj/xcshareddata/xcschemes/Compressor.xcscheme +0 -67
- package/ios/Compressor.xcodeproj/xcuserdata/apple.xcuserdatad/xcschemes/xcschememanagement.plist +0 -22
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
</div>
|
|
4
4
|
<br/>
|
|
5
5
|
|
|
6
|
+
<div align="center">
|
|
7
|
+
|
|
8
|
+
[](https://discord.gg/dtYzk8sp)
|
|
9
|
+
[](https://github.com/numandev1/react-native-compressor/stargazers)
|
|
10
|
+
[](https://www.npmjs.com/package/react-native-compressor)
|
|
11
|
+

|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
6
16
|
**REACT-NATIVE-COMPRESSOR** is a react-native package, which help us to Compress `Image`, `Video`, and `Audio` same like **Whatsapp** without knowing compression `algorithm`
|
|
7
17
|
|
|
8
18
|
<div align="center">
|
|
@@ -66,19 +76,13 @@ We should use **react-native-compressor** instead of **FFmpeg** because **react-
|
|
|
66
76
|
|
|
67
77
|
## Installation
|
|
68
78
|
|
|
69
|
-
### React Native
|
|
70
|
-
|
|
71
|
-
#### For React Native<0.65
|
|
72
|
-
|
|
73
79
|
```sh
|
|
74
|
-
yarn add react-native-compressor
|
|
80
|
+
yarn add react-native-compressor
|
|
75
81
|
```
|
|
76
82
|
|
|
77
|
-
|
|
83
|
+
### [New Architecture (Turbo Module)](https://reactnative.dev/docs/new-architecture-intro) Supported
|
|
84
|
+
you can give feedback on [Discord channel](https://discord.gg/dtYzk8sp)
|
|
78
85
|
|
|
79
|
-
```sh
|
|
80
|
-
yarn add react-native-compressor
|
|
81
|
-
```
|
|
82
86
|
|
|
83
87
|
### Managed Expo
|
|
84
88
|
|
|
@@ -330,9 +334,9 @@ const uploadResult = await backgroundUpload(
|
|
|
330
334
|
|
|
331
335
|
bitrate of video which reduce or increase video size. if compressionMethod will auto then this prop will not work
|
|
332
336
|
|
|
333
|
-
- ###### `minimumFileSizeForCompress: number` (default:
|
|
337
|
+
- ###### `minimumFileSizeForCompress: number` (default: 0)
|
|
334
338
|
|
|
335
|
-
16
|
|
339
|
+
previously default was 16 but now it is 0 by default. 0 mean 0mb. This is an offset, which you can set for minimumFileSizeForCompress will allow this package to dont compress less than or equal to `minimumFileSizeForCompress` ref [#26](https://github.com/numandev1/react-native-compressor/issues/26)
|
|
336
340
|
|
|
337
341
|
- ###### `getCancellationId: function`
|
|
338
342
|
`getCancellationId` is a callback function that gives us compress video id, which can be used in `Video.cancelCompression` method to cancel the compression
|
package/android/build.gradle
CHANGED
|
@@ -1,62 +1,115 @@
|
|
|
1
1
|
buildscript {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
repositories {
|
|
3
|
+
google()
|
|
4
|
+
mavenCentral()
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
dependencies {
|
|
8
|
+
classpath "com.android.tools.build:gradle:7.2.1"
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
def isNewArchitectureEnabled() {
|
|
13
|
+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
apply plugin: "com.android.library"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
|
|
20
|
+
|
|
21
|
+
if (isNewArchitectureEnabled()) {
|
|
22
|
+
apply plugin: "com.facebook.react"
|
|
12
23
|
}
|
|
13
24
|
|
|
14
|
-
|
|
25
|
+
def getExtOrDefault(name) {
|
|
26
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["Compressor_" + name]
|
|
27
|
+
}
|
|
15
28
|
|
|
16
|
-
def
|
|
17
|
-
|
|
29
|
+
def getExtOrIntegerDefault(name) {
|
|
30
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Compressor_" + name]).toInteger()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
def supportsNamespace() {
|
|
34
|
+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
35
|
+
def major = parsed[0].toInteger()
|
|
36
|
+
def minor = parsed[1].toInteger()
|
|
37
|
+
|
|
38
|
+
// Namespace support was added in 7.3.0
|
|
39
|
+
if (major == 7 && minor >= 3) {
|
|
40
|
+
return true
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return major >= 8
|
|
18
44
|
}
|
|
19
45
|
|
|
20
46
|
android {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
defaultConfig {
|
|
24
|
-
minSdkVersion safeExtGet('minSdkVersion', 16)
|
|
25
|
-
targetSdkVersion safeExtGet('targetSdkVersion', 29)
|
|
26
|
-
versionCode 1
|
|
27
|
-
versionName "1.0"
|
|
47
|
+
if (supportsNamespace()) {
|
|
48
|
+
namespace "com.reactnativecompressor"
|
|
28
49
|
|
|
50
|
+
sourceSets {
|
|
51
|
+
main {
|
|
52
|
+
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
53
|
+
}
|
|
29
54
|
}
|
|
55
|
+
}
|
|
30
56
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
57
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
58
|
+
|
|
59
|
+
defaultConfig {
|
|
60
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
61
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
62
|
+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
63
|
+
}
|
|
64
|
+
buildTypes {
|
|
65
|
+
release {
|
|
66
|
+
minifyEnabled false
|
|
38
67
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
lintOptions {
|
|
71
|
+
disable "GradleCompatible"
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
compileOptions {
|
|
75
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
76
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
sourceSets {
|
|
80
|
+
main {
|
|
81
|
+
if (isNewArchitectureEnabled()) {
|
|
82
|
+
java.srcDirs += [
|
|
83
|
+
"src/newarch",
|
|
84
|
+
// This is needed to build Kotlin project with NewArch enabled
|
|
85
|
+
"${project.buildDir}/generated/source/codegen/java"
|
|
86
|
+
]
|
|
87
|
+
} else {
|
|
88
|
+
java.srcDirs += ["src/oldarch"]
|
|
89
|
+
}
|
|
42
90
|
}
|
|
91
|
+
}
|
|
43
92
|
}
|
|
44
93
|
|
|
45
94
|
repositories {
|
|
46
|
-
|
|
47
|
-
|
|
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" }
|
|
95
|
+
mavenCentral()
|
|
96
|
+
google()
|
|
54
97
|
}
|
|
55
98
|
|
|
99
|
+
|
|
56
100
|
dependencies {
|
|
57
|
-
|
|
58
|
-
|
|
101
|
+
// For < 0.71, this will be from the local maven repo
|
|
102
|
+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
103
|
+
//noinspection GradleDynamicVersion
|
|
104
|
+
implementation "com.facebook.react:react-native:+"
|
|
59
105
|
implementation 'io.github.lizhangqu:coreprogress:1.0.2'
|
|
60
|
-
implementation 'com.github.numandev1:VideoCompressor:
|
|
61
|
-
|
|
106
|
+
implementation 'com.github.numandev1:VideoCompressor:1a262bba37'
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (isNewArchitectureEnabled()) {
|
|
110
|
+
react {
|
|
111
|
+
jsRootDir = file("../src/")
|
|
112
|
+
libraryName = "Compressor"
|
|
113
|
+
codegenJavaPackageName = "com.reactnativecompressor"
|
|
114
|
+
}
|
|
62
115
|
}
|
|
@@ -1,49 +1,56 @@
|
|
|
1
1
|
package com.reactnativecompressor;
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.bridge.Promise;
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
7
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
7
8
|
|
|
8
9
|
import androidx.annotation.NonNull;
|
|
9
10
|
import androidx.annotation.Nullable;
|
|
10
11
|
import androidx.annotation.RequiresApi;
|
|
11
12
|
|
|
12
13
|
import com.facebook.react.bridge.Arguments;
|
|
13
|
-
import com.facebook.react.bridge.Promise;
|
|
14
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
15
14
|
import com.facebook.react.bridge.ReactContext;
|
|
16
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
17
|
-
import com.facebook.react.bridge.ReactMethod;
|
|
18
15
|
import com.facebook.react.bridge.ReadableMap;
|
|
19
16
|
import com.facebook.react.bridge.WritableMap;
|
|
20
|
-
import com.facebook.react.module.annotations.ReactModule;
|
|
21
17
|
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
22
18
|
import com.reactnativecompressor.Image.ImageCompressor;
|
|
23
19
|
import com.reactnativecompressor.Image.utils.ImageCompressorOptions;
|
|
24
20
|
import com.reactnativecompressor.Utils.Utils;
|
|
25
21
|
import com.reactnativecompressor.Video.VideoCompressorHelper;
|
|
22
|
+
import com.reactnativecompressor.CompressorSpec;
|
|
26
23
|
import static com.reactnativecompressor.Utils.Utils.generateCacheFilePath;
|
|
27
|
-
|
|
24
|
+
|
|
25
|
+
import android.content.ContentResolver;
|
|
26
|
+
import android.content.res.AssetFileDescriptor;
|
|
27
|
+
import android.database.Cursor;
|
|
28
|
+
import android.media.MediaMetadataRetriever;
|
|
29
|
+
import android.net.Uri;
|
|
30
|
+
import android.os.Build;
|
|
31
|
+
import android.provider.OpenableColumns;
|
|
32
|
+
import android.util.Log;
|
|
28
33
|
|
|
29
34
|
import com.reactnativecompressor.Audio.AudioCompressor;
|
|
30
35
|
|
|
31
36
|
import java.io.File;
|
|
37
|
+
import java.io.FileNotFoundException;
|
|
32
38
|
|
|
33
|
-
|
|
34
|
-
public
|
|
35
|
-
public static final String NAME = "Compressor";
|
|
39
|
+
public class CompressorModule extends CompressorSpec {
|
|
40
|
+
public static final String NAME = "Compressor";
|
|
36
41
|
private final ReactApplicationContext reactContext;
|
|
37
|
-
public CompressorModule(ReactApplicationContext reactContext) {
|
|
38
|
-
super(reactContext);
|
|
39
|
-
this.reactContext = reactContext;
|
|
40
|
-
}
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
CompressorModule(ReactApplicationContext context) {
|
|
44
|
+
super(context);
|
|
45
|
+
this.reactContext = context;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@Override
|
|
49
|
+
@NonNull
|
|
50
|
+
public String getName() {
|
|
51
|
+
return NAME;
|
|
52
|
+
}
|
|
53
|
+
|
|
47
54
|
|
|
48
55
|
private void sendEvent(ReactContext reactContext,
|
|
49
56
|
String eventName,
|
|
@@ -53,7 +60,7 @@ public class CompressorModule extends ReactContextBaseJavaModule {
|
|
|
53
60
|
.emit(eventName, params);
|
|
54
61
|
}
|
|
55
62
|
|
|
56
|
-
|
|
63
|
+
//Image
|
|
57
64
|
@ReactMethod
|
|
58
65
|
public void image_compress(
|
|
59
66
|
String imagePath,
|
|
@@ -78,8 +85,8 @@ public class CompressorModule extends ReactContextBaseJavaModule {
|
|
|
78
85
|
}
|
|
79
86
|
}
|
|
80
87
|
|
|
81
|
-
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
|
|
82
88
|
@ReactMethod
|
|
89
|
+
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
|
|
83
90
|
public void compress_audio(
|
|
84
91
|
String fileUrl,
|
|
85
92
|
ReadableMap optionMap,
|
|
@@ -104,15 +111,15 @@ public class CompressorModule extends ReactContextBaseJavaModule {
|
|
|
104
111
|
|
|
105
112
|
|
|
106
113
|
//General
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
@ReactMethod
|
|
115
|
+
public void generateFilePath(String extension, Promise promise) {
|
|
116
|
+
try {
|
|
117
|
+
final String outputUri =generateCacheFilePath(extension,reactContext);
|
|
118
|
+
promise.resolve(outputUri);
|
|
119
|
+
} catch (Exception e) {
|
|
120
|
+
promise.reject(e);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
116
123
|
|
|
117
124
|
@ReactMethod
|
|
118
125
|
public void getRealPath(String path,String type, Promise promise) {
|
|
@@ -153,4 +160,52 @@ public class CompressorModule extends ReactContextBaseJavaModule {
|
|
|
153
160
|
promise.reject(e);
|
|
154
161
|
}
|
|
155
162
|
}
|
|
163
|
+
@ReactMethod
|
|
164
|
+
public void getFileSize(String filePath, Promise promise)
|
|
165
|
+
{
|
|
166
|
+
filePath=Utils.getRealPath(filePath,reactContext);
|
|
167
|
+
Uri uri= Uri.parse(filePath);
|
|
168
|
+
ContentResolver contentResolver = reactContext.getContentResolver();
|
|
169
|
+
long fileSize = getLength(uri, contentResolver);
|
|
170
|
+
if (fileSize >= 0) {
|
|
171
|
+
promise.resolve(String.valueOf(fileSize));
|
|
172
|
+
} else {
|
|
173
|
+
promise.resolve("");
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
public static long getLength(Uri uri, ContentResolver contentResolver) {
|
|
178
|
+
AssetFileDescriptor assetFileDescriptor = null;
|
|
179
|
+
try {
|
|
180
|
+
assetFileDescriptor = contentResolver.openAssetFileDescriptor(uri, "r");
|
|
181
|
+
} catch (FileNotFoundException e) {
|
|
182
|
+
// Do nothing
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
long length = (assetFileDescriptor != null) ? assetFileDescriptor.getLength() : -1L;
|
|
186
|
+
if (length != -1L) {
|
|
187
|
+
return length;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) {
|
|
191
|
+
Cursor cursor = contentResolver.query(uri, new String[]{OpenableColumns.SIZE}, null, null, null);
|
|
192
|
+
if (cursor != null) {
|
|
193
|
+
try {
|
|
194
|
+
int sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE);
|
|
195
|
+
if (sizeIndex != -1 && cursor.moveToFirst()) {
|
|
196
|
+
try {
|
|
197
|
+
return cursor.getLong(sizeIndex);
|
|
198
|
+
} catch (Throwable ignored) {
|
|
199
|
+
return -1L;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
} finally {
|
|
203
|
+
cursor.close();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return -1L;
|
|
207
|
+
} else {
|
|
208
|
+
return -1L;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
156
211
|
}
|
|
@@ -1,30 +1,58 @@
|
|
|
1
1
|
package com.reactnativecompressor;
|
|
2
2
|
|
|
3
|
-
import androidx.annotation.
|
|
3
|
+
import androidx.annotation.Nullable;
|
|
4
4
|
|
|
5
|
-
import com.facebook.react.ReactPackage;
|
|
6
5
|
import com.facebook.react.bridge.NativeModule;
|
|
7
6
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
8
|
-
import com.facebook.react.
|
|
7
|
+
import com.facebook.react.module.model.ReactModuleInfo;
|
|
8
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider;
|
|
9
|
+
import com.facebook.react.TurboReactPackage;
|
|
10
|
+
import java.util.HashMap;
|
|
11
|
+
import java.util.Map;
|
|
9
12
|
import com.reactnativecompressor.Video.VideoModule;
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
import java.util.Collections;
|
|
13
|
-
import java.util.List;
|
|
14
|
+
public class CompressorPackage extends TurboReactPackage {
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
@Nullable
|
|
17
|
+
@Override
|
|
18
|
+
public NativeModule getModule(String name, ReactApplicationContext reactContext) {
|
|
19
|
+
if (name.equals(CompressorModule.NAME)) {
|
|
20
|
+
return new CompressorModule(reactContext);
|
|
21
|
+
} else if (name.equals(VideoModule.NAME)) {
|
|
22
|
+
return new VideoModule(reactContext);
|
|
23
|
+
} else {
|
|
24
|
+
return null;
|
|
23
25
|
}
|
|
26
|
+
}
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
@Override
|
|
29
|
+
public ReactModuleInfoProvider getReactModuleInfoProvider() {
|
|
30
|
+
return () -> {
|
|
31
|
+
final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
|
|
32
|
+
boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
|
|
33
|
+
moduleInfos.put(
|
|
34
|
+
CompressorModule.NAME,
|
|
35
|
+
new ReactModuleInfo(
|
|
36
|
+
CompressorModule.NAME,
|
|
37
|
+
CompressorModule.NAME,
|
|
38
|
+
false, // canOverrideExistingModule
|
|
39
|
+
false, // needsEagerInit
|
|
40
|
+
true, // hasConstants
|
|
41
|
+
false, // isCxxModule
|
|
42
|
+
isTurboModule // isTurboModule
|
|
43
|
+
));
|
|
44
|
+
moduleInfos.put(
|
|
45
|
+
VideoModule.NAME,
|
|
46
|
+
new ReactModuleInfo(
|
|
47
|
+
VideoModule.NAME,
|
|
48
|
+
VideoModule.NAME,
|
|
49
|
+
false, // canOverrideExistingModule
|
|
50
|
+
false, // needsEagerInit
|
|
51
|
+
true, // hasConstants
|
|
52
|
+
false, // isCxxModule
|
|
53
|
+
isTurboModule // isTurboModule
|
|
54
|
+
));
|
|
55
|
+
return moduleInfos;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
30
58
|
}
|
package/android/src/main/java/com/reactnativecompressor/Image/utils/ImageCompressorOptions.java
CHANGED
|
@@ -55,7 +55,7 @@ public class ImageCompressorOptions {
|
|
|
55
55
|
auto, manual
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
public CompressionMethod compressionMethod = CompressionMethod.
|
|
58
|
+
public CompressionMethod compressionMethod = CompressionMethod.auto;
|
|
59
59
|
public int maxWidth = 1280;
|
|
60
60
|
public int maxHeight = 1280;
|
|
61
61
|
public float quality = 0.8f;
|
|
@@ -105,7 +105,7 @@ public class Utils {
|
|
|
105
105
|
fileUrl= RealPathUtil.getRealPath(reactContext,uri);
|
|
106
106
|
}
|
|
107
107
|
catch (Exception ex) {
|
|
108
|
-
Log.d(TAG, " Please see this issue: https://github.com/
|
|
108
|
+
Log.d(TAG, " Please see this issue: https://github.com/numandev1/react-native-compressor/issues/25");
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
return fileUrl;
|
|
@@ -96,11 +96,11 @@ public class VideoCompressorHelper {
|
|
|
96
96
|
auto, manual
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
public VideoCompressorHelper.CompressionMethod compressionMethod = VideoCompressorHelper.CompressionMethod.
|
|
99
|
+
public VideoCompressorHelper.CompressionMethod compressionMethod = VideoCompressorHelper.CompressionMethod.auto;
|
|
100
100
|
public float bitrate = 0;
|
|
101
101
|
public String uuid = "";
|
|
102
102
|
public float maxSize = 640.0f;
|
|
103
|
-
public float minimumFileSizeForCompress =
|
|
103
|
+
public float minimumFileSizeForCompress = 0.0f;
|
|
104
104
|
|
|
105
105
|
public static VideoCompressorHelper fromMap(ReadableMap map) {
|
|
106
106
|
final VideoCompressorHelper options = new VideoCompressorHelper();
|
|
@@ -116,12 +116,15 @@ public class VideoCompressorHelper {
|
|
|
116
116
|
case "maxSize":
|
|
117
117
|
options.maxSize = (float) map.getDouble(key);
|
|
118
118
|
break;
|
|
119
|
-
|
|
119
|
+
case "uuid":
|
|
120
120
|
options.uuid = map.getString(key);
|
|
121
121
|
break;
|
|
122
122
|
case "minimumFileSizeForCompress":
|
|
123
123
|
options.minimumFileSizeForCompress =(float) map.getDouble(key);
|
|
124
124
|
break;
|
|
125
|
+
case "bitrate":
|
|
126
|
+
options.bitrate = (float) map.getDouble(key);
|
|
127
|
+
break;
|
|
125
128
|
|
|
126
129
|
}
|
|
127
130
|
}
|
|
@@ -149,7 +152,7 @@ public class VideoCompressorHelper {
|
|
|
149
152
|
int bitrate=Integer.parseInt(metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE));
|
|
150
153
|
|
|
151
154
|
boolean isPortrait = height > width;
|
|
152
|
-
int maxSize =
|
|
155
|
+
int maxSize = (int) options.maxSize;
|
|
153
156
|
if(isPortrait && height > maxSize){
|
|
154
157
|
width = (int) (((float)maxSize/height)*width);
|
|
155
158
|
height = maxSize;
|
|
@@ -15,6 +15,7 @@ import com.facebook.react.bridge.ReadableMap;
|
|
|
15
15
|
import com.facebook.react.bridge.WritableMap;
|
|
16
16
|
import com.facebook.react.module.annotations.ReactModule;
|
|
17
17
|
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
18
|
+
import com.reactnativecompressor.VideoCompressorSpec;
|
|
18
19
|
import com.reactnativecompressor.Utils.RealPathUtil;
|
|
19
20
|
|
|
20
21
|
import static com.reactnativecompressor.Utils.Utils.getRealPath;
|
|
@@ -23,14 +24,15 @@ import static com.reactnativecompressor.Video.VideoCompressorHelper.video_deacti
|
|
|
23
24
|
import static com.reactnativecompressor.Video.VideoCompressorHelper.video_upload_helper;
|
|
24
25
|
import static com.reactnativecompressor.Utils.Utils.cancelCompressionHelper;
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
public class
|
|
27
|
+
|
|
28
|
+
public class VideoModule extends VideoCompressorSpec {
|
|
28
29
|
public static final String NAME = "VideoCompressor";
|
|
29
30
|
private static final String TAG = "react-native-compessor";
|
|
30
31
|
private final ReactApplicationContext reactContext;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
|
|
33
|
+
public VideoModule(ReactApplicationContext context) {
|
|
34
|
+
super(context);
|
|
35
|
+
this.reactContext = context;
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
@NonNull
|
|
@@ -117,7 +119,7 @@ public class VideoModule extends ReactContextBaseJavaModule {
|
|
|
117
119
|
}
|
|
118
120
|
|
|
119
121
|
@ReactMethod
|
|
120
|
-
public void removeListeners(
|
|
122
|
+
public void removeListeners(double count) {
|
|
121
123
|
// Keep: Required for RN built in Event Emitter Calls.
|
|
122
124
|
}
|
|
123
125
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
public abstract void getRealPath(String path,String type, Promise promise);
|
|
25
|
+
public abstract void getVideoMetaData(String filePath, Promise promise);
|
|
26
|
+
|
|
27
|
+
public abstract void getFileSize(String filePath, Promise promise);
|
|
28
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
}
|