Skip to content

Commit 3052c87

Browse files
Merge pull request #139 from SimformSolutionsPvtLtd/develop
Release v2.1.2
2 parents de8db71 + 7b44723 commit 3052c87

File tree

15 files changed

+318
-114
lines changed

15 files changed

+318
-114
lines changed

android/src/main/java/com/audiowaveform/AudioWaveformModule.kt

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,10 @@ class AudioWaveformModule(context: ReactApplicationContext): ReactContextBaseJav
159159
@ReactMethod
160160
fun startPlayer(obj: ReadableMap, promise: Promise) {
161161
val finishMode = obj.getInt(Constants.finishMode)
162-
val key = obj.getString(Constants.playerKey)
163162
val speed = obj.getDouble(Constants.speed)
164-
if (key != null) {
165-
audioPlayers[key]?.start(finishMode ?: 2, speed.toFloat(),promise)
166-
} else {
167-
promise.reject("startPlayer Error", "Player key can't be null")
168-
}
163+
164+
val player = getPlayerOrReject(obj, promise, "startPlayer Error");
165+
player?.start(finishMode ?: 2, speed.toFloat(),promise)
169166
}
170167

171168
@ReactMethod
@@ -182,25 +179,18 @@ class AudioWaveformModule(context: ReactApplicationContext): ReactContextBaseJav
182179

183180
@ReactMethod
184181
fun pausePlayer(obj: ReadableMap, promise: Promise) {
185-
val key = obj.getString(Constants.playerKey)
186-
if (key != null) {
187-
audioPlayers[key]?.pause(promise)
188-
} else {
189-
promise.reject("pausePlayer Error", "Player key can't be null")
190-
}
182+
val player = getPlayerOrReject(obj, promise, "pausePlayer Error");
183+
player?.pause(promise);
191184
}
192185

193186
@ReactMethod
194187
fun seekToPlayer(obj: ReadableMap, promise: Promise) {
195188
try {
196189
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
197190
val progress = obj.getInt(Constants.progress)
198-
val key = obj.getString(Constants.playerKey)
199-
if (key != null) {
200-
audioPlayers[key]?.seekToPosition(progress.toLong(), promise)
201-
} else {
202-
promise.reject("seekTo Error", "Player key can't be null")
203-
}
191+
192+
val player = getPlayerOrReject(obj, promise, "seekTo Error");
193+
player?.seekToPosition(progress.toLong(), promise)
204194
} else {
205195
Log.e(
206196
Constants.LOG_TAG,
@@ -216,24 +206,18 @@ class AudioWaveformModule(context: ReactApplicationContext): ReactContextBaseJav
216206
@ReactMethod
217207
fun setVolume(obj: ReadableMap, promise: Promise) {
218208
val volume = obj.getInt(Constants.volume)
219-
val key = obj.getString(Constants.playerKey)
220-
if (key != null) {
221-
audioPlayers[key]?.setVolume(volume.toFloat(), promise)
222-
} else {
223-
promise.reject("setVolume error", "Player key can't be null")
224-
}
209+
210+
val player = getPlayerOrReject(obj, promise, "setVolume Error");
211+
player?.setVolume(volume.toFloat(), promise)
225212
}
226213

227214
@ReactMethod
228215
fun getDuration(obj: ReadableMap, promise: Promise) {
229-
val key = obj.getString(Constants.playerKey)
230216
val duration = obj.getInt(Constants.durationType)
231217
val type = if (duration == 0) DurationType.Current else DurationType.Max
232-
if (key != null) {
233-
audioPlayers[key]?.getDuration(type, promise)
234-
} else {
235-
promise.reject("getDuration Error", "Player key can't be null")
236-
}
218+
219+
val player = getPlayerOrReject(obj, promise, "getDuration Error");
220+
player?.getDuration(type, promise)
237221
}
238222

239223
@ReactMethod
@@ -316,7 +300,7 @@ class AudioWaveformModule(context: ReactApplicationContext): ReactContextBaseJav
316300
}
317301
}
318302
override fun onReject(error: String?, message: String?) {
319-
promise.reject(error, message)
303+
promise.reject(error ?: "Error", message ?: "An error is thrown while decoding the audio file")
320304
}
321305
override fun onResolve(value: MutableList<MutableList<Float>>) {
322306
promise.resolve(Arguments.fromList(value))
@@ -429,4 +413,18 @@ class AudioWaveformModule(context: ReactApplicationContext): ReactContextBaseJav
429413
handler.removeCallbacks(emitLiveRecordValue)
430414
}
431415

416+
private fun getPlayerOrReject(arguments: ReadableMap, promise: Promise, errorCode: String): AudioPlayer? {
417+
val key = getPlayerKeyOrReject(arguments, promise, errorCode)
418+
return audioPlayers[key] ?: run {
419+
promise.reject(errorCode, "$errorCode: Player not in the list")
420+
null
421+
}
422+
}
423+
424+
private fun getPlayerKeyOrReject(arguments: ReadableMap, promise: Promise, errorCode: String): String? {
425+
return arguments.getString(Constants.playerKey) ?: run {
426+
promise.reject(errorCode, "$errorCode: Player key can't be null")
427+
null
428+
}
429+
}
432430
}

example/ios/Podfile.lock

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ PODS:
7474
- hermes-engine/Pre-built (= 0.72.7)
7575
- hermes-engine/Pre-built (0.72.7)
7676
- libevent (2.1.12)
77+
- libwebp (1.3.2):
78+
- libwebp/demux (= 1.3.2)
79+
- libwebp/mux (= 1.3.2)
80+
- libwebp/sharpyuv (= 1.3.2)
81+
- libwebp/webp (= 1.3.2)
82+
- libwebp/demux (1.3.2):
83+
- libwebp/webp
84+
- libwebp/mux (1.3.2):
85+
- libwebp/demux
86+
- libwebp/sharpyuv (1.3.2)
87+
- libwebp/webp (1.3.2):
88+
- libwebp/sharpyuv
7789
- OpenSSL-Universal (1.1.1100)
7890
- RCT-Folly (2021.07.22.00):
7991
- boost
@@ -378,7 +390,7 @@ PODS:
378390
- react-native-audio-waveform (1.0.0):
379391
- RCT-Folly (= 2021.07.22.00)
380392
- React-Core
381-
- react-native-safe-area-context (4.9.0):
393+
- react-native-safe-area-context (4.11.0):
382394
- React-Core
383395
- React-NativeModulesApple (0.72.7):
384396
- hermes-engine
@@ -492,11 +504,21 @@ PODS:
492504
- React-perflogger (= 0.72.7)
493505
- rn-fetch-blob (0.12.0):
494506
- React-Core
507+
- RNFastImage (8.6.3):
508+
- React-Core
509+
- SDWebImage (~> 5.11.1)
510+
- SDWebImageWebPCoder (~> 0.8.4)
495511
- RNFS (2.20.0):
496512
- React-Core
497-
- RNGestureHandler (2.14.0):
513+
- RNGestureHandler (2.19.0):
498514
- RCT-Folly (= 2021.07.22.00)
499515
- React-Core
516+
- SDWebImage (5.11.1):
517+
- SDWebImage/Core (= 5.11.1)
518+
- SDWebImage/Core (5.11.1)
519+
- SDWebImageWebPCoder (0.8.5):
520+
- libwebp (~> 1.0)
521+
- SDWebImage/Core (~> 5.10)
500522
- SocketRocket (0.6.1)
501523
- Yoga (1.14.0)
502524
- YogaKit (1.18.1):
@@ -568,6 +590,7 @@ DEPENDENCIES:
568590
- React-utils (from `../node_modules/react-native/ReactCommon/react/utils`)
569591
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
570592
- rn-fetch-blob (from `../node_modules/rn-fetch-blob`)
593+
- RNFastImage (from `../node_modules/react-native-fast-image`)
571594
- RNFS (from `../node_modules/react-native-fs`)
572595
- RNGestureHandler (from `../node_modules/react-native-gesture-handler`)
573596
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)
@@ -585,7 +608,10 @@ SPEC REPOS:
585608
- FlipperKit
586609
- fmt
587610
- libevent
611+
- libwebp
588612
- OpenSSL-Universal
613+
- SDWebImage
614+
- SDWebImageWebPCoder
589615
- SocketRocket
590616
- YogaKit
591617

@@ -673,6 +699,8 @@ EXTERNAL SOURCES:
673699
:path: "../node_modules/react-native/ReactCommon"
674700
rn-fetch-blob:
675701
:path: "../node_modules/rn-fetch-blob"
702+
RNFastImage:
703+
:path: "../node_modules/react-native-fast-image"
676704
RNFS:
677705
:path: "../node_modules/react-native-fs"
678706
RNGestureHandler:
@@ -698,6 +726,7 @@ SPEC CHECKSUMS:
698726
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
699727
hermes-engine: 9180d43df05c1ed658a87cc733dc3044cf90c00a
700728
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
729+
libwebp: 1786c9f4ff8a279e4dac1e8f385004d5fc253009
701730
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
702731
RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1
703732
RCTRequired: 83bca1c184feb4d2e51c72c8369b83d641443f95
@@ -715,7 +744,7 @@ SPEC CHECKSUMS:
715744
React-jsinspector: 8baadae51f01d867c3921213a25ab78ab4fbcd91
716745
React-logger: 8edc785c47c8686c7962199a307015e2ce9a0e4f
717746
react-native-audio-waveform: 7cdb6e4963eeae907240396975b9c79713591758
718-
react-native-safe-area-context: b97eb6f9e3b7f437806c2ce5983f479f8eb5de4b
747+
react-native-safe-area-context: 851c62c48dce80ccaa5637b6aa5991a1bc36eca9
719748
React-NativeModulesApple: b6868ee904013a7923128892ee4a032498a1024a
720749
React-perflogger: 31ea61077185eb1428baf60c0db6e2886f141a5a
721750
React-RCTActionSheet: 392090a3abc8992eb269ef0eaa561750588fc39d
@@ -734,8 +763,11 @@ SPEC CHECKSUMS:
734763
React-utils: 56838edeaaf651220d1e53cd0b8934fb8ce68415
735764
ReactCommon: 5f704096ccf7733b390f59043b6fa9cc180ee4f6
736765
rn-fetch-blob: f065bb7ab7fb48dd002629f8bdcb0336602d3cba
766+
RNFastImage: 5c9c9fed9c076e521b3f509fe79e790418a544e8
737767
RNFS: 4ac0f0ea233904cb798630b3c077808c06931688
738-
RNGestureHandler: 32a01c29ecc9bb0b5bf7bc0a33547f61b4dc2741
768+
RNGestureHandler: 7ad14a6c7b491add489246611d324f10009083ac
769+
SDWebImage: a7f831e1a65eb5e285e3fb046a23fcfbf08e696d
770+
SDWebImageWebPCoder: 908b83b6adda48effe7667cd2b7f78c897e5111d
739771
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
740772
Yoga: 4c3aa327e4a6a23eeacd71f61c81df1bcdf677d5
741773
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

example/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"dependencies": {
1313
"react": "18.2.0",
1414
"react-native": "0.72.7",
15+
"react-native-fast-image": "^8.6.3",
1516
"react-native-fs": "^2.20.0",
1617
"react-native-gesture-handler": "^2.13.4",
1718
"react-native-safe-area-context": "^4.9.0",

0 commit comments

Comments
 (0)