react-native-compressor 1.8.4 → 1.8.6
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 +5 -6
- package/android/build.gradle +3 -0
- package/android/src/main/java/com/reactnativecompressor/Audio/AudioCompressor.kt +174 -496
- package/android/src/main/java/com/reactnativecompressor/Audio/AudioHelper.kt +23 -0
- package/android/src/main/java/com/reactnativecompressor/Audio/AudioMain.kt +5 -13
- package/android/src/main/java/com/reactnativecompressor/Utils/RealPathUtil.kt +74 -8
- package/android/src/main/java/com/reactnativecompressor/Utils/Utils.kt +5 -0
- package/lib/commonjs/Audio/index.js +3 -42
- package/lib/commonjs/Audio/index.js.map +1 -1
- package/lib/commonjs/utils/index.js +5 -44
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/module/Audio/index.js +4 -43
- package/lib/module/Audio/index.js.map +1 -1
- package/lib/module/utils/index.js +5 -39
- package/lib/module/utils/index.js.map +1 -1
- package/lib/typescript/Audio/index.d.ts.map +1 -1
- package/lib/typescript/expo-plugin/compressor.d.ts +3 -1
- package/lib/typescript/expo-plugin/compressor.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +1 -1
- package/lib/typescript/utils/index.d.ts +1 -6
- package/lib/typescript/utils/index.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/Audio/index.tsx +5 -56
- package/src/utils/index.tsx +4 -54
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-compressor",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.6",
|
|
4
4
|
"description": "This library compress image, video and audio",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -82,15 +82,16 @@
|
|
|
82
82
|
"eslint-config-prettier": "^8.5.0",
|
|
83
83
|
"eslint-plugin-ft-flow": "^3.0.0",
|
|
84
84
|
"eslint-plugin-prettier": "^5.0.0",
|
|
85
|
-
"prettier": "^3.0.1",
|
|
86
85
|
"jest": "^28.1.1",
|
|
87
86
|
"pod-install": "^0.1.0",
|
|
87
|
+
"prettier": "^3.0.1",
|
|
88
88
|
"react": "18.2.0",
|
|
89
89
|
"react-native": "0.72.4",
|
|
90
90
|
"react-native-builder-bob": "^0.20.0",
|
|
91
91
|
"release-it": "^15.0.0",
|
|
92
92
|
"turbo": "^1.10.7",
|
|
93
|
-
"typescript": "^5.0.2"
|
|
93
|
+
"typescript": "^5.0.2",
|
|
94
|
+
"@expo/config-plugins": "^7.2.5"
|
|
94
95
|
},
|
|
95
96
|
"resolutions": {
|
|
96
97
|
"@types/react": "17.0.21"
|
package/src/Audio/index.tsx
CHANGED
|
@@ -1,66 +1,15 @@
|
|
|
1
1
|
import { Compressor } from '../Main';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
DEFAULT_COMPRESS_AUDIO_OPTIONS,
|
|
6
|
-
checkUrlAndOptions,
|
|
7
|
-
} from '../utils';
|
|
8
|
-
import type { AudioType, defaultResultType } from '../utils';
|
|
3
|
+
import { DEFAULT_COMPRESS_AUDIO_OPTIONS } from '../utils';
|
|
4
|
+
import type { AudioType } from '../utils';
|
|
9
5
|
const NativeAudio = Compressor;
|
|
10
6
|
|
|
11
7
|
const Audio: AudioType = {
|
|
12
8
|
compress: async (url, options = DEFAULT_COMPRESS_AUDIO_OPTIONS) => {
|
|
13
9
|
try {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
throw checkUrlAndOptionsResult.message;
|
|
18
|
-
} else {
|
|
19
|
-
// Get resulting output file path
|
|
20
|
-
|
|
21
|
-
// Get media details
|
|
22
|
-
// const mediaDetails: any = await getDetails(url).catch(() => null);
|
|
23
|
-
const mediaDetails: any = {
|
|
24
|
-
bitrate: 0,
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// Initialize bitrate
|
|
28
|
-
let bitrate: any = DEFAULT_COMPRESS_AUDIO_OPTIONS.bitrate;
|
|
29
|
-
|
|
30
|
-
if (mediaDetails && mediaDetails.bitrate) {
|
|
31
|
-
// Check and return the appropriate bitrate according to quality expected
|
|
32
|
-
for (let i = 0; i < AUDIO_BITRATE.length; i++) {
|
|
33
|
-
// Check a particular bitrate to return its nearest lower according to quality
|
|
34
|
-
//@ts-ignore
|
|
35
|
-
if (mediaDetails.bitrate > AUDIO_BITRATE[i]) {
|
|
36
|
-
if (i + 2 < AUDIO_BITRATE.length) {
|
|
37
|
-
if (options.quality === 'low') bitrate = AUDIO_BITRATE[i + 2];
|
|
38
|
-
else if (options.quality === 'medium')
|
|
39
|
-
bitrate = AUDIO_BITRATE[i + 1];
|
|
40
|
-
else bitrate = AUDIO_BITRATE[i];
|
|
41
|
-
} else if (i + 1 < AUDIO_BITRATE.length) {
|
|
42
|
-
if (options.quality === 'low') bitrate = AUDIO_BITRATE[i + 1];
|
|
43
|
-
else bitrate = AUDIO_BITRATE[i];
|
|
44
|
-
} else bitrate = AUDIO_BITRATE[i];
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Check if the matching bitrate is the last in the array
|
|
49
|
-
if (
|
|
50
|
-
//@ts-ignore
|
|
51
|
-
mediaDetails.bitrate <= AUDIO_BITRATE[AUDIO_BITRATE.length - 1]
|
|
52
|
-
) {
|
|
53
|
-
bitrate = AUDIO_BITRATE[AUDIO_BITRATE.length - 1];
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return NativeAudio.compress_audio(url, {
|
|
60
|
-
bitrate,
|
|
61
|
-
quality: options.quality,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
10
|
+
return NativeAudio.compress_audio(url, {
|
|
11
|
+
quality: options.quality,
|
|
12
|
+
});
|
|
64
13
|
} catch (error: any) {
|
|
65
14
|
throw error.message;
|
|
66
15
|
}
|
package/src/utils/index.tsx
CHANGED
|
@@ -1,29 +1,22 @@
|
|
|
1
1
|
/* eslint-disable no-bitwise */
|
|
2
2
|
import { Compressor } from '../Main';
|
|
3
3
|
|
|
4
|
-
export const AUDIO_BITRATE = [256, 192, 160, 128, 96, 64, 32];
|
|
4
|
+
// export const AUDIO_BITRATE = [256, 192, 160, 128, 96, 64, 32];
|
|
5
5
|
type qualityType = 'low' | 'medium' | 'high';
|
|
6
6
|
const INCORRECT_INPUT_PATH = 'Incorrect input path. Please provide a valid one';
|
|
7
|
-
const INCORRECT_OUTPUT_PATH =
|
|
8
|
-
'Incorrect output path. Please provide a valid one';
|
|
9
|
-
const ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE =
|
|
10
|
-
'An error occur while generating output file';
|
|
11
7
|
type audioCompresssionType = {
|
|
12
|
-
bitrate?: number;
|
|
8
|
+
// bitrate?: number;
|
|
13
9
|
quality: qualityType;
|
|
14
|
-
outputFilePath?: string | undefined | null;
|
|
15
10
|
};
|
|
16
11
|
|
|
17
12
|
export type defaultResultType = {
|
|
18
|
-
outputFilePath: string | undefined | null;
|
|
19
13
|
isCorrect: boolean;
|
|
20
14
|
message: string;
|
|
21
15
|
};
|
|
22
16
|
|
|
23
17
|
export const DEFAULT_COMPRESS_AUDIO_OPTIONS: audioCompresssionType = {
|
|
24
|
-
bitrate: 96,
|
|
18
|
+
// bitrate: 96,
|
|
25
19
|
quality: 'medium',
|
|
26
|
-
outputFilePath: '',
|
|
27
20
|
};
|
|
28
21
|
|
|
29
22
|
export type AudioType = {
|
|
@@ -47,7 +40,7 @@ type clearCacheType = (cacheDir?: string) => Promise<string>;
|
|
|
47
40
|
type getVideoMetaDataType = (filePath: string) => Promise<string>;
|
|
48
41
|
type getRealPathType = (
|
|
49
42
|
path: string,
|
|
50
|
-
type: 'video' | '
|
|
43
|
+
type: 'video' | 'image'
|
|
51
44
|
) => Promise<string>;
|
|
52
45
|
|
|
53
46
|
export const generateFilePath: any = (extension: string) => {
|
|
@@ -152,49 +145,6 @@ export const getDetails = (
|
|
|
152
145
|
});
|
|
153
146
|
};
|
|
154
147
|
|
|
155
|
-
export const checkUrlAndOptions = async (
|
|
156
|
-
url: string,
|
|
157
|
-
options: audioCompresssionType
|
|
158
|
-
): Promise<defaultResultType> => {
|
|
159
|
-
if (!url) {
|
|
160
|
-
throw new Error(
|
|
161
|
-
'Compression url is empty, please provide a url for compression.'
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
const defaultResult: defaultResultType = {
|
|
165
|
-
outputFilePath: '',
|
|
166
|
-
isCorrect: true,
|
|
167
|
-
message: '',
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
// Check if output file is correct
|
|
171
|
-
let outputFilePath: string | undefined | null;
|
|
172
|
-
try {
|
|
173
|
-
// use default output file
|
|
174
|
-
// or use new file from cache folder
|
|
175
|
-
if (options.outputFilePath) {
|
|
176
|
-
outputFilePath = options.outputFilePath;
|
|
177
|
-
defaultResult.outputFilePath = outputFilePath;
|
|
178
|
-
} else {
|
|
179
|
-
outputFilePath = await generateFilePath('mp3');
|
|
180
|
-
defaultResult.outputFilePath = outputFilePath;
|
|
181
|
-
}
|
|
182
|
-
if (outputFilePath === undefined || outputFilePath === null) {
|
|
183
|
-
defaultResult.isCorrect = false;
|
|
184
|
-
defaultResult.message = options.outputFilePath
|
|
185
|
-
? INCORRECT_OUTPUT_PATH
|
|
186
|
-
: ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;
|
|
187
|
-
}
|
|
188
|
-
} catch (e) {
|
|
189
|
-
defaultResult.isCorrect = false;
|
|
190
|
-
defaultResult.message = options.outputFilePath
|
|
191
|
-
? INCORRECT_OUTPUT_PATH
|
|
192
|
-
: ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;
|
|
193
|
-
} finally {
|
|
194
|
-
return defaultResult;
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
|
|
198
148
|
export const getFileSize = async (filePath: string): Promise<string> => {
|
|
199
149
|
return Compressor.getFileSize(filePath);
|
|
200
150
|
};
|