react-native-compressor 1.8.5 → 1.8.7
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 -4
- package/android/build.gradle +3 -1
- package/android/src/main/java/com/reactnativecompressor/Audio/AudioCompressor.kt +202 -496
- package/android/src/main/java/com/reactnativecompressor/Audio/AudioExtractor.kt +112 -0
- 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/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 +1 -1
- package/src/Audio/index.tsx +5 -56
- package/src/utils/index.tsx +4 -54
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
package com.reactnativecompressor.Audio
|
|
2
|
+
|
|
3
|
+
import android.annotation.SuppressLint
|
|
4
|
+
import android.media.MediaCodec
|
|
5
|
+
import android.media.MediaExtractor
|
|
6
|
+
import android.media.MediaFormat
|
|
7
|
+
import android.media.MediaMetadataRetriever
|
|
8
|
+
import android.media.MediaMuxer
|
|
9
|
+
import android.util.Log
|
|
10
|
+
import java.io.IOException
|
|
11
|
+
import java.nio.ByteBuffer
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class AudioExtractor {
|
|
15
|
+
/**
|
|
16
|
+
* @param srcPath the path of source video file.
|
|
17
|
+
* @param dstPath the path of destination video file.
|
|
18
|
+
* @param startMs starting time in milliseconds for trimming. Set to
|
|
19
|
+
* negative if starting from beginning.
|
|
20
|
+
* @param endMs end time for trimming in milliseconds. Set to negative if
|
|
21
|
+
* no trimming at the end.
|
|
22
|
+
* @param useAudio true if keep the audio track from the source.
|
|
23
|
+
* @param useVideo true if keep the video track from the source.
|
|
24
|
+
* @throws IOException
|
|
25
|
+
*/
|
|
26
|
+
@SuppressLint("NewApi", "WrongConstant")
|
|
27
|
+
@Throws(IOException::class)
|
|
28
|
+
fun genVideoUsingMuxer(srcPath: String?, dstPath: String?, startMs: Int, endMs: Int, useAudio: Boolean, useVideo: Boolean) {
|
|
29
|
+
// Set up MediaExtractor to read from the source.
|
|
30
|
+
val extractor = MediaExtractor()
|
|
31
|
+
extractor.setDataSource(srcPath!!)
|
|
32
|
+
val trackCount = extractor.trackCount
|
|
33
|
+
// Set up MediaMuxer for the destination.
|
|
34
|
+
val muxer: MediaMuxer
|
|
35
|
+
muxer = MediaMuxer(dstPath!!, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4)
|
|
36
|
+
// Set up the tracks and retrieve the max buffer size for selected
|
|
37
|
+
// tracks.
|
|
38
|
+
val indexMap = HashMap<Int, Int>(trackCount)
|
|
39
|
+
var bufferSize = -1
|
|
40
|
+
for (i in 0 until trackCount) {
|
|
41
|
+
val format = extractor.getTrackFormat(i)
|
|
42
|
+
val mime = format.getString(MediaFormat.KEY_MIME)
|
|
43
|
+
var selectCurrentTrack = false
|
|
44
|
+
if (mime!!.startsWith("audio/") && useAudio) {
|
|
45
|
+
selectCurrentTrack = true
|
|
46
|
+
} else if (mime.startsWith("video/") && useVideo) {
|
|
47
|
+
selectCurrentTrack = true
|
|
48
|
+
}
|
|
49
|
+
if (selectCurrentTrack) {
|
|
50
|
+
extractor.selectTrack(i)
|
|
51
|
+
val dstIndex = muxer.addTrack(format)
|
|
52
|
+
indexMap[i] = dstIndex
|
|
53
|
+
if (format.containsKey(MediaFormat.KEY_MAX_INPUT_SIZE)) {
|
|
54
|
+
val newSize = format.getInteger(MediaFormat.KEY_MAX_INPUT_SIZE)
|
|
55
|
+
bufferSize = if (newSize > bufferSize) newSize else bufferSize
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (bufferSize < 0) {
|
|
60
|
+
bufferSize = DEFAULT_BUFFER_SIZE
|
|
61
|
+
}
|
|
62
|
+
// Set up the orientation and starting time for extractor.
|
|
63
|
+
val retrieverSrc = MediaMetadataRetriever()
|
|
64
|
+
retrieverSrc.setDataSource(srcPath)
|
|
65
|
+
val degreesString = retrieverSrc.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION)
|
|
66
|
+
if (degreesString != null) {
|
|
67
|
+
val degrees = degreesString.toInt()
|
|
68
|
+
if (degrees >= 0) {
|
|
69
|
+
muxer.setOrientationHint(degrees)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (startMs > 0) {
|
|
73
|
+
extractor.seekTo((startMs * 1000).toLong(), MediaExtractor.SEEK_TO_CLOSEST_SYNC)
|
|
74
|
+
}
|
|
75
|
+
// Copy the samples from MediaExtractor to MediaMuxer. We will loop
|
|
76
|
+
// for copying each sample and stop when we get to the end of the source
|
|
77
|
+
// file or exceed the end time of the trimming.
|
|
78
|
+
val offset = 0
|
|
79
|
+
var trackIndex = -1
|
|
80
|
+
val dstBuf = ByteBuffer.allocate(bufferSize)
|
|
81
|
+
val bufferInfo = MediaCodec.BufferInfo()
|
|
82
|
+
muxer.start()
|
|
83
|
+
while (true) {
|
|
84
|
+
bufferInfo.offset = offset
|
|
85
|
+
bufferInfo.size = extractor.readSampleData(dstBuf, offset)
|
|
86
|
+
if (bufferInfo.size < 0) {
|
|
87
|
+
Log.d(TAG, "Saw input EOS.")
|
|
88
|
+
bufferInfo.size = 0
|
|
89
|
+
break
|
|
90
|
+
} else {
|
|
91
|
+
bufferInfo.presentationTimeUs = extractor.sampleTime
|
|
92
|
+
if (endMs > 0 && bufferInfo.presentationTimeUs > endMs * 1000) {
|
|
93
|
+
Log.d(TAG, "The current sample is over the trim end time.")
|
|
94
|
+
break
|
|
95
|
+
} else {
|
|
96
|
+
bufferInfo.flags = extractor.sampleFlags
|
|
97
|
+
trackIndex = extractor.sampleTrackIndex
|
|
98
|
+
muxer.writeSampleData(indexMap[trackIndex]!!, dstBuf, bufferInfo)
|
|
99
|
+
extractor.advance()
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
muxer.stop()
|
|
104
|
+
muxer.release()
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
companion object {
|
|
109
|
+
private const val DEFAULT_BUFFER_SIZE = 1 * 1024 * 1024
|
|
110
|
+
private const val TAG = "AudioExtractorDecoder"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
package com.reactnativecompressor.Audio
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReadableMap
|
|
4
|
+
|
|
5
|
+
class AudioHelper {
|
|
6
|
+
|
|
7
|
+
var quality: String? = "medium"
|
|
8
|
+
var progressDivider: Int? = 0
|
|
9
|
+
|
|
10
|
+
companion object {
|
|
11
|
+
fun fromMap(map: ReadableMap): AudioHelper {
|
|
12
|
+
val options = AudioHelper()
|
|
13
|
+
val iterator = map.keySetIterator()
|
|
14
|
+
while (iterator.hasNextKey()) {
|
|
15
|
+
val key = iterator.nextKey()
|
|
16
|
+
when (key) {
|
|
17
|
+
"quality" -> options.quality = map.getString(key)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return options
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
package com.reactnativecompressor.Audio
|
|
2
2
|
|
|
3
|
-
import android.media.MediaMetadataRetriever
|
|
4
|
-
import android.net.Uri
|
|
5
|
-
import android.util.Log
|
|
6
3
|
import com.facebook.react.bridge.Promise
|
|
7
4
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
8
5
|
import com.facebook.react.bridge.ReadableMap
|
|
9
6
|
import com.reactnativecompressor.Utils.Utils
|
|
10
|
-
import com.reactnativecompressor.Video.VideoCompressorHelper
|
|
11
7
|
|
|
12
8
|
class AudioMain(private val reactContext: ReactApplicationContext) {
|
|
13
9
|
fun compress_audio(
|
|
@@ -15,15 +11,11 @@ class AudioMain(private val reactContext: ReactApplicationContext) {
|
|
|
15
11
|
optionMap: ReadableMap,
|
|
16
12
|
promise: Promise) {
|
|
17
13
|
try {
|
|
18
|
-
val options =
|
|
19
|
-
val
|
|
20
|
-
val
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
metaRetriever.setDataSource(srcPath)
|
|
24
|
-
val bitrate = options.bitrate
|
|
25
|
-
Log.d("nomi onStart", destinationPath + "onProgress: " + bitrate)
|
|
26
|
-
AudioCompressor().CompressAudio(srcPath, destinationPath, bitrate.toInt() * 1000)
|
|
14
|
+
val options = AudioHelper.fromMap(optionMap)
|
|
15
|
+
val quality = options.quality
|
|
16
|
+
val realPath = Utils.getRealPath(fileUrl, reactContext)
|
|
17
|
+
Utils.addLog(fileUrl + "\n realPath= " + realPath)
|
|
18
|
+
AudioCompressor.CompressAudio(realPath!!, quality!!,reactContext,promise)
|
|
27
19
|
} catch (ex: Exception) {
|
|
28
20
|
promise.reject(ex)
|
|
29
21
|
}
|
|
@@ -9,10 +9,21 @@ import android.os.Build
|
|
|
9
9
|
import android.os.Environment
|
|
10
10
|
import android.provider.DocumentsContract
|
|
11
11
|
import android.provider.MediaStore
|
|
12
|
+
import android.provider.OpenableColumns
|
|
12
13
|
import androidx.loader.content.CursorLoader
|
|
14
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
15
|
+
import java.io.File
|
|
16
|
+
import java.io.FileOutputStream
|
|
17
|
+
import java.io.IOException
|
|
18
|
+
import java.util.UUID
|
|
19
|
+
|
|
13
20
|
|
|
14
21
|
object RealPathUtil {
|
|
15
|
-
|
|
22
|
+
|
|
23
|
+
private const val FIELD_NAME = "name"
|
|
24
|
+
private const val FIELD_TYPE = "type"
|
|
25
|
+
private const val FIELD_SIZE = "size"
|
|
26
|
+
fun getRealPath(context: ReactApplicationContext, fileUri: Uri): String? {
|
|
16
27
|
val realPath: String?
|
|
17
28
|
// SDK < API11
|
|
18
29
|
realPath = if (Build.VERSION.SDK_INT < 11) {
|
|
@@ -65,7 +76,7 @@ object RealPathUtil {
|
|
|
65
76
|
* @author paulburke
|
|
66
77
|
*/
|
|
67
78
|
@SuppressLint("NewApi")
|
|
68
|
-
fun getRealPathFromURI_API19(context:
|
|
79
|
+
fun getRealPathFromURI_API19(context: ReactApplicationContext, uri: Uri): String? {
|
|
69
80
|
val isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
|
|
70
81
|
|
|
71
82
|
// DocumentProvider
|
|
@@ -84,7 +95,7 @@ object RealPathUtil {
|
|
|
84
95
|
val id = DocumentsContract.getDocumentId(uri)
|
|
85
96
|
val contentUri = ContentUris.withAppendedId(
|
|
86
97
|
Uri.parse("content://downloads/public_downloads"), java.lang.Long.valueOf(id))
|
|
87
|
-
return getDataColumn(context, contentUri, null, null)
|
|
98
|
+
return getDataColumn(context, contentUri, null, null,uri)
|
|
88
99
|
} else if (isMediaDocument(uri)) {
|
|
89
100
|
val docId = DocumentsContract.getDocumentId(uri)
|
|
90
101
|
val split = docId.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
|
@@ -96,17 +107,19 @@ object RealPathUtil {
|
|
|
96
107
|
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI
|
|
97
108
|
} else if ("audio" == type) {
|
|
98
109
|
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
|
|
110
|
+
}else {
|
|
111
|
+
contentUri = MediaStore.Files.getContentUri("external");
|
|
99
112
|
}
|
|
100
113
|
val selection = "_id=?"
|
|
101
114
|
val selectionArgs = arrayOf(
|
|
102
115
|
split[1]
|
|
103
116
|
)
|
|
104
|
-
return getDataColumn(context, contentUri, selection, selectionArgs)
|
|
117
|
+
return getDataColumn(context, contentUri, selection, selectionArgs,uri)
|
|
105
118
|
}
|
|
106
119
|
} else if ("content".equals(uri.scheme, ignoreCase = true)) {
|
|
107
120
|
|
|
108
121
|
// Return the remote address
|
|
109
|
-
return if (isGooglePhotosUri(uri)) uri.lastPathSegment else getDataColumn(context, uri, null, null)
|
|
122
|
+
return if (isGooglePhotosUri(uri)) uri.lastPathSegment else getDataColumn(context, uri, null, null,uri)
|
|
110
123
|
} else if ("file".equals(uri.scheme, ignoreCase = true)) {
|
|
111
124
|
return uri.path
|
|
112
125
|
}
|
|
@@ -123,8 +136,8 @@ object RealPathUtil {
|
|
|
123
136
|
* @param selectionArgs (Optional) Selection arguments used in the query.
|
|
124
137
|
* @return The value of the _data column, which is typically a file path.
|
|
125
138
|
*/
|
|
126
|
-
fun getDataColumn(context:
|
|
127
|
-
selectionArgs: Array<String
|
|
139
|
+
fun getDataColumn(context: ReactApplicationContext, uri: Uri?, selection: String?,
|
|
140
|
+
selectionArgs: Array<String>?,actualUri: Uri?): String? {
|
|
128
141
|
var cursor: Cursor? = null
|
|
129
142
|
val column = "_data"
|
|
130
143
|
val projection = arrayOf(
|
|
@@ -137,13 +150,66 @@ object RealPathUtil {
|
|
|
137
150
|
val index = cursor.getColumnIndexOrThrow(column)
|
|
138
151
|
return cursor.getString(index)
|
|
139
152
|
}
|
|
153
|
+
|
|
154
|
+
val copyPath=copyFileToLocalStorage(actualUri!!, context)
|
|
155
|
+
MediaCache.addCompletedImagePath(copyPath)
|
|
156
|
+
return copyPath
|
|
157
|
+
} catch (e: Exception) {
|
|
158
|
+
val copyPath=copyFileToLocalStorage(actualUri!!, context)
|
|
159
|
+
MediaCache.addCompletedImagePath(copyPath)
|
|
160
|
+
return copyPath
|
|
140
161
|
} finally {
|
|
141
162
|
cursor?.close()
|
|
142
163
|
}
|
|
143
164
|
return null
|
|
144
165
|
}
|
|
145
166
|
|
|
146
|
-
|
|
167
|
+
fun getFileExtension(fileName: String): String {
|
|
168
|
+
return if (fileName.contains(".")) {
|
|
169
|
+
fileName.substringAfterLast(".")
|
|
170
|
+
} else {
|
|
171
|
+
""
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
private fun copyFileToLocalStorage( uri: Uri,context: ReactApplicationContext): String {
|
|
176
|
+
val returnUri = uri
|
|
177
|
+
val returnCursor = context.contentResolver.query(returnUri, null, null, null, null)
|
|
178
|
+
returnCursor?.moveToFirst();
|
|
179
|
+
val nameIndex = returnCursor!!.getColumnIndex(OpenableColumns.DISPLAY_NAME)
|
|
180
|
+
val name = returnCursor!!.getString(nameIndex)
|
|
181
|
+
val fileExtension=getFileExtension(name)
|
|
182
|
+
var dir = context.cacheDir
|
|
183
|
+
|
|
184
|
+
// we don't want to rename the file so we put it into a unique location
|
|
185
|
+
dir = File(dir, UUID.randomUUID().toString())
|
|
186
|
+
try {
|
|
187
|
+
val destPath=Utils.generateCacheFilePath(fileExtension, context)
|
|
188
|
+
val destFile = File(destPath)
|
|
189
|
+
val copyPath: Uri = copyFile(context, uri, destFile)
|
|
190
|
+
return copyPath.toString()
|
|
191
|
+
} catch (e: java.lang.Exception) {
|
|
192
|
+
e.printStackTrace()
|
|
193
|
+
}
|
|
194
|
+
return uri.toString()
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
@Throws(IOException::class)
|
|
198
|
+
fun copyFile(context: Context, uri: Uri?, destFile: File?): Uri {
|
|
199
|
+
context.contentResolver.openInputStream(uri!!).use { inputStream ->
|
|
200
|
+
FileOutputStream(destFile).use { outputStream ->
|
|
201
|
+
val buf = ByteArray(8192)
|
|
202
|
+
var len: Int
|
|
203
|
+
while (inputStream!!.read(buf).also { len = it } > 0) {
|
|
204
|
+
outputStream.write(buf, 0, len)
|
|
205
|
+
}
|
|
206
|
+
return Uri.fromFile(destFile)
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
/**
|
|
147
213
|
* @param uri The Uri to check.
|
|
148
214
|
* @return Whether the Uri authority is ExternalStorageProvider.
|
|
149
215
|
*/
|
|
@@ -7,6 +7,7 @@ import android.provider.OpenableColumns
|
|
|
7
7
|
import android.util.Log
|
|
8
8
|
import com.facebook.react.bridge.Promise
|
|
9
9
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
10
|
+
import com.reactnativecompressor.Audio.AudioCompressor
|
|
10
11
|
import com.reactnativecompressor.Video.VideoCompressor.CompressionListener
|
|
11
12
|
import com.reactnativecompressor.Video.VideoCompressor.VideoCompressorClass
|
|
12
13
|
import java.io.FileNotFoundException
|
|
@@ -133,6 +134,10 @@ object Utils {
|
|
|
133
134
|
}
|
|
134
135
|
}
|
|
135
136
|
|
|
137
|
+
fun addLog(log: String) {
|
|
138
|
+
Log.d(AudioCompressor.TAG, log)
|
|
139
|
+
}
|
|
140
|
+
|
|
136
141
|
fun getLength(uri: Uri, contentResolver: ContentResolver): Long {
|
|
137
142
|
var assetFileDescriptor: AssetFileDescriptor? = null
|
|
138
143
|
try {
|
|
@@ -11,48 +11,9 @@ const Audio = {
|
|
|
11
11
|
compress: async function (url) {
|
|
12
12
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _utils.DEFAULT_COMPRESS_AUDIO_OPTIONS;
|
|
13
13
|
try {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} else {
|
|
18
|
-
// Get resulting output file path
|
|
19
|
-
|
|
20
|
-
// Get media details
|
|
21
|
-
// const mediaDetails: any = await getDetails(url).catch(() => null);
|
|
22
|
-
const mediaDetails = {
|
|
23
|
-
bitrate: 0
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// Initialize bitrate
|
|
27
|
-
let bitrate = _utils.DEFAULT_COMPRESS_AUDIO_OPTIONS.bitrate;
|
|
28
|
-
if (mediaDetails && mediaDetails.bitrate) {
|
|
29
|
-
// Check and return the appropriate bitrate according to quality expected
|
|
30
|
-
for (let i = 0; i < _utils.AUDIO_BITRATE.length; i++) {
|
|
31
|
-
// Check a particular bitrate to return its nearest lower according to quality
|
|
32
|
-
//@ts-ignore
|
|
33
|
-
if (mediaDetails.bitrate > _utils.AUDIO_BITRATE[i]) {
|
|
34
|
-
if (i + 2 < _utils.AUDIO_BITRATE.length) {
|
|
35
|
-
if (options.quality === 'low') bitrate = _utils.AUDIO_BITRATE[i + 2];else if (options.quality === 'medium') bitrate = _utils.AUDIO_BITRATE[i + 1];else bitrate = _utils.AUDIO_BITRATE[i];
|
|
36
|
-
} else if (i + 1 < _utils.AUDIO_BITRATE.length) {
|
|
37
|
-
if (options.quality === 'low') bitrate = _utils.AUDIO_BITRATE[i + 1];else bitrate = _utils.AUDIO_BITRATE[i];
|
|
38
|
-
} else bitrate = _utils.AUDIO_BITRATE[i];
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Check if the matching bitrate is the last in the array
|
|
43
|
-
if (
|
|
44
|
-
//@ts-ignore
|
|
45
|
-
mediaDetails.bitrate <= _utils.AUDIO_BITRATE[_utils.AUDIO_BITRATE.length - 1]) {
|
|
46
|
-
bitrate = _utils.AUDIO_BITRATE[_utils.AUDIO_BITRATE.length - 1];
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return NativeAudio.compress_audio(url, {
|
|
52
|
-
bitrate,
|
|
53
|
-
quality: options.quality
|
|
54
|
-
});
|
|
55
|
-
}
|
|
14
|
+
return NativeAudio.compress_audio(url, {
|
|
15
|
+
quality: options.quality
|
|
16
|
+
});
|
|
56
17
|
} catch (error) {
|
|
57
18
|
throw error.message;
|
|
58
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_Main","require","_utils","NativeAudio","Compressor","Audio","compress","url","options","arguments","length","undefined","DEFAULT_COMPRESS_AUDIO_OPTIONS","
|
|
1
|
+
{"version":3,"names":["_Main","require","_utils","NativeAudio","Compressor","Audio","compress","url","options","arguments","length","undefined","DEFAULT_COMPRESS_AUDIO_OPTIONS","compress_audio","quality","error","message","_default","exports","default"],"sourceRoot":"../../../src","sources":["Audio/index.tsx"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAEA,MAAME,WAAW,GAAGC,gBAAU;AAE9B,MAAMC,KAAgB,GAAG;EACvBC,QAAQ,EAAE,eAAAA,CAAOC,GAAG,EAA+C;IAAA,IAA7CC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAGG,qCAA8B;IAC5D,IAAI;MACF,OAAOT,WAAW,CAACU,cAAc,CAACN,GAAG,EAAE;QACrCO,OAAO,EAAEN,OAAO,CAACM;MACnB,CAAC,CAAC;IACJ,CAAC,CAAC,OAAOC,KAAU,EAAE;MACnB,MAAMA,KAAK,CAACC,OAAO;IACrB;EACF;AACF,CAAC;AAAC,IAAAC,QAAA,GAEaZ,KAAK;AAAAa,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
var _exportNames = {
|
|
7
|
-
AUDIO_BITRATE: true,
|
|
8
7
|
DEFAULT_COMPRESS_AUDIO_OPTIONS: true,
|
|
9
8
|
generateFilePath: true,
|
|
10
9
|
getRealPath: true,
|
|
@@ -12,11 +11,10 @@ var _exportNames = {
|
|
|
12
11
|
createVideoThumbnail: true,
|
|
13
12
|
clearCache: true,
|
|
14
13
|
getDetails: true,
|
|
15
|
-
checkUrlAndOptions: true,
|
|
16
14
|
getFileSize: true,
|
|
17
15
|
uuidv4: true
|
|
18
16
|
};
|
|
19
|
-
exports.uuidv4 = exports.getVideoMetaData = exports.getRealPath = exports.getFileSize = exports.getDetails = exports.generateFilePath = exports.createVideoThumbnail = exports.clearCache = exports.
|
|
17
|
+
exports.uuidv4 = exports.getVideoMetaData = exports.getRealPath = exports.getFileSize = exports.getDetails = exports.generateFilePath = exports.createVideoThumbnail = exports.clearCache = exports.DEFAULT_COMPRESS_AUDIO_OPTIONS = void 0;
|
|
20
18
|
var _Main = require("../Main");
|
|
21
19
|
var _Downloader = require("./Downloader");
|
|
22
20
|
Object.keys(_Downloader).forEach(function (key) {
|
|
@@ -44,15 +42,12 @@ Object.keys(_Uploader).forEach(function (key) {
|
|
|
44
42
|
});
|
|
45
43
|
/* eslint-disable no-bitwise */
|
|
46
44
|
|
|
47
|
-
const AUDIO_BITRATE = [256, 192, 160, 128, 96, 64, 32];
|
|
48
|
-
|
|
45
|
+
// export const AUDIO_BITRATE = [256, 192, 160, 128, 96, 64, 32];
|
|
46
|
+
|
|
49
47
|
const INCORRECT_INPUT_PATH = 'Incorrect input path. Please provide a valid one';
|
|
50
|
-
const INCORRECT_OUTPUT_PATH = 'Incorrect output path. Please provide a valid one';
|
|
51
|
-
const ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE = 'An error occur while generating output file';
|
|
52
48
|
const DEFAULT_COMPRESS_AUDIO_OPTIONS = {
|
|
53
|
-
bitrate: 96,
|
|
54
|
-
quality: 'medium'
|
|
55
|
-
outputFilePath: ''
|
|
49
|
+
// bitrate: 96,
|
|
50
|
+
quality: 'medium'
|
|
56
51
|
};
|
|
57
52
|
exports.DEFAULT_COMPRESS_AUDIO_OPTIONS = DEFAULT_COMPRESS_AUDIO_OPTIONS;
|
|
58
53
|
const generateFilePath = extension => {
|
|
@@ -142,40 +137,6 @@ const getDetails = function (mediaFullPath) {
|
|
|
142
137
|
});
|
|
143
138
|
};
|
|
144
139
|
exports.getDetails = getDetails;
|
|
145
|
-
const checkUrlAndOptions = async (url, options) => {
|
|
146
|
-
if (!url) {
|
|
147
|
-
throw new Error('Compression url is empty, please provide a url for compression.');
|
|
148
|
-
}
|
|
149
|
-
const defaultResult = {
|
|
150
|
-
outputFilePath: '',
|
|
151
|
-
isCorrect: true,
|
|
152
|
-
message: ''
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
// Check if output file is correct
|
|
156
|
-
let outputFilePath;
|
|
157
|
-
try {
|
|
158
|
-
// use default output file
|
|
159
|
-
// or use new file from cache folder
|
|
160
|
-
if (options.outputFilePath) {
|
|
161
|
-
outputFilePath = options.outputFilePath;
|
|
162
|
-
defaultResult.outputFilePath = outputFilePath;
|
|
163
|
-
} else {
|
|
164
|
-
outputFilePath = await generateFilePath('mp3');
|
|
165
|
-
defaultResult.outputFilePath = outputFilePath;
|
|
166
|
-
}
|
|
167
|
-
if (outputFilePath === undefined || outputFilePath === null) {
|
|
168
|
-
defaultResult.isCorrect = false;
|
|
169
|
-
defaultResult.message = options.outputFilePath ? INCORRECT_OUTPUT_PATH : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;
|
|
170
|
-
}
|
|
171
|
-
} catch (e) {
|
|
172
|
-
defaultResult.isCorrect = false;
|
|
173
|
-
defaultResult.message = options.outputFilePath ? INCORRECT_OUTPUT_PATH : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;
|
|
174
|
-
} finally {
|
|
175
|
-
return defaultResult;
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
exports.checkUrlAndOptions = checkUrlAndOptions;
|
|
179
140
|
const getFileSize = async filePath => {
|
|
180
141
|
return _Main.Compressor.getFileSize(filePath);
|
|
181
142
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_Main","require","_Downloader","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_Uploader","
|
|
1
|
+
{"version":3,"names":["_Main","require","_Downloader","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_Uploader","INCORRECT_INPUT_PATH","DEFAULT_COMPRESS_AUDIO_OPTIONS","quality","generateFilePath","extension","Promise","resolve","reject","Compressor","then","result","catch","error","getRealPath","path","type","arguments","length","undefined","getVideoMetaData","createVideoThumbnail","fileUrl","options","clearCache","cacheDir","isValidUrl","url","test","getFullFilename","_path","includes","substring","array","split","isFileNameError","filename","getFilename","fullFilename","slice","join","isRemoteMedia","_path$split","getDetails","mediaFullPath","extesnion","Error","mediaInfo","JSON","parse","mediaInformation","bitrate","getMediaProperties","bit_rate","size","Number","format","e","getFileSize","filePath","uuidv4","replace","c","r","parseFloat","Math","random","toString","Date","getTime","v"],"sourceRoot":"../../../src","sources":["utils/index.tsx"],"mappings":";;;;;;;;;;;;;;;;;AACA,IAAAA,KAAA,GAAAC,OAAA;AAqKA,IAAAC,WAAA,GAAAD,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAF,WAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,WAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,WAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,SAAA,GAAAd,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAW,SAAA,EAAAV,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAS,SAAA,CAA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} from '../Main';
|
|
2
|
-
import {
|
|
2
|
+
import { DEFAULT_COMPRESS_AUDIO_OPTIONS } from '../utils';
|
|
3
3
|
const NativeAudio = Compressor;
|
|
4
4
|
const Audio = {
|
|
5
5
|
compress: async function (url) {
|
|
6
6
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_COMPRESS_AUDIO_OPTIONS;
|
|
7
7
|
try {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} else {
|
|
12
|
-
// Get resulting output file path
|
|
13
|
-
|
|
14
|
-
// Get media details
|
|
15
|
-
// const mediaDetails: any = await getDetails(url).catch(() => null);
|
|
16
|
-
const mediaDetails = {
|
|
17
|
-
bitrate: 0
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
// Initialize bitrate
|
|
21
|
-
let bitrate = DEFAULT_COMPRESS_AUDIO_OPTIONS.bitrate;
|
|
22
|
-
if (mediaDetails && mediaDetails.bitrate) {
|
|
23
|
-
// Check and return the appropriate bitrate according to quality expected
|
|
24
|
-
for (let i = 0; i < AUDIO_BITRATE.length; i++) {
|
|
25
|
-
// Check a particular bitrate to return its nearest lower according to quality
|
|
26
|
-
//@ts-ignore
|
|
27
|
-
if (mediaDetails.bitrate > AUDIO_BITRATE[i]) {
|
|
28
|
-
if (i + 2 < AUDIO_BITRATE.length) {
|
|
29
|
-
if (options.quality === 'low') bitrate = AUDIO_BITRATE[i + 2];else if (options.quality === 'medium') bitrate = AUDIO_BITRATE[i + 1];else bitrate = AUDIO_BITRATE[i];
|
|
30
|
-
} else if (i + 1 < AUDIO_BITRATE.length) {
|
|
31
|
-
if (options.quality === 'low') bitrate = AUDIO_BITRATE[i + 1];else bitrate = AUDIO_BITRATE[i];
|
|
32
|
-
} else bitrate = AUDIO_BITRATE[i];
|
|
33
|
-
break;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Check if the matching bitrate is the last in the array
|
|
37
|
-
if (
|
|
38
|
-
//@ts-ignore
|
|
39
|
-
mediaDetails.bitrate <= AUDIO_BITRATE[AUDIO_BITRATE.length - 1]) {
|
|
40
|
-
bitrate = AUDIO_BITRATE[AUDIO_BITRATE.length - 1];
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return NativeAudio.compress_audio(url, {
|
|
46
|
-
bitrate,
|
|
47
|
-
quality: options.quality
|
|
48
|
-
});
|
|
49
|
-
}
|
|
8
|
+
return NativeAudio.compress_audio(url, {
|
|
9
|
+
quality: options.quality
|
|
10
|
+
});
|
|
50
11
|
} catch (error) {
|
|
51
12
|
throw error.message;
|
|
52
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Compressor","
|
|
1
|
+
{"version":3,"names":["Compressor","DEFAULT_COMPRESS_AUDIO_OPTIONS","NativeAudio","Audio","compress","url","options","arguments","length","undefined","compress_audio","quality","error","message"],"sourceRoot":"../../../src","sources":["Audio/index.tsx"],"mappings":"AAAA,SAASA,UAAU,QAAQ,SAAS;AAEpC,SAASC,8BAA8B,QAAQ,UAAU;AAEzD,MAAMC,WAAW,GAAGF,UAAU;AAE9B,MAAMG,KAAgB,GAAG;EACvBC,QAAQ,EAAE,eAAAA,CAAOC,GAAG,EAA+C;IAAA,IAA7CC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAGN,8BAA8B;IAC5D,IAAI;MACF,OAAOC,WAAW,CAACQ,cAAc,CAACL,GAAG,EAAE;QACrCM,OAAO,EAAEL,OAAO,CAACK;MACnB,CAAC,CAAC;IACJ,CAAC,CAAC,OAAOC,KAAU,EAAE;MACnB,MAAMA,KAAK,CAACC,OAAO;IACrB;EACF;AACF,CAAC;AAED,eAAeV,KAAK"}
|
|
@@ -1,13 +1,12 @@
|
|
|
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];
|
|
5
|
+
|
|
4
6
|
const INCORRECT_INPUT_PATH = 'Incorrect input path. Please provide a valid one';
|
|
5
|
-
const INCORRECT_OUTPUT_PATH = 'Incorrect output path. Please provide a valid one';
|
|
6
|
-
const ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE = 'An error occur while generating output file';
|
|
7
7
|
export const DEFAULT_COMPRESS_AUDIO_OPTIONS = {
|
|
8
|
-
bitrate: 96,
|
|
9
|
-
quality: 'medium'
|
|
10
|
-
outputFilePath: ''
|
|
8
|
+
// bitrate: 96,
|
|
9
|
+
quality: 'medium'
|
|
11
10
|
};
|
|
12
11
|
export const generateFilePath = extension => {
|
|
13
12
|
return new Promise((resolve, reject) => {
|
|
@@ -90,39 +89,6 @@ export const getDetails = function (mediaFullPath) {
|
|
|
90
89
|
}
|
|
91
90
|
});
|
|
92
91
|
};
|
|
93
|
-
export const checkUrlAndOptions = async (url, options) => {
|
|
94
|
-
if (!url) {
|
|
95
|
-
throw new Error('Compression url is empty, please provide a url for compression.');
|
|
96
|
-
}
|
|
97
|
-
const defaultResult = {
|
|
98
|
-
outputFilePath: '',
|
|
99
|
-
isCorrect: true,
|
|
100
|
-
message: ''
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
// Check if output file is correct
|
|
104
|
-
let outputFilePath;
|
|
105
|
-
try {
|
|
106
|
-
// use default output file
|
|
107
|
-
// or use new file from cache folder
|
|
108
|
-
if (options.outputFilePath) {
|
|
109
|
-
outputFilePath = options.outputFilePath;
|
|
110
|
-
defaultResult.outputFilePath = outputFilePath;
|
|
111
|
-
} else {
|
|
112
|
-
outputFilePath = await generateFilePath('mp3');
|
|
113
|
-
defaultResult.outputFilePath = outputFilePath;
|
|
114
|
-
}
|
|
115
|
-
if (outputFilePath === undefined || outputFilePath === null) {
|
|
116
|
-
defaultResult.isCorrect = false;
|
|
117
|
-
defaultResult.message = options.outputFilePath ? INCORRECT_OUTPUT_PATH : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;
|
|
118
|
-
}
|
|
119
|
-
} catch (e) {
|
|
120
|
-
defaultResult.isCorrect = false;
|
|
121
|
-
defaultResult.message = options.outputFilePath ? INCORRECT_OUTPUT_PATH : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;
|
|
122
|
-
} finally {
|
|
123
|
-
return defaultResult;
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
92
|
export const getFileSize = async filePath => {
|
|
127
93
|
return Compressor.getFileSize(filePath);
|
|
128
94
|
};
|