Skip to content

Commit

Permalink
Merge pull request #139 from SimformSolutionsPvtLtd/develop
Browse files Browse the repository at this point in the history
Release v2.1.2
  • Loading branch information
mukesh-simform authored Nov 19, 2024
2 parents de8db71 + 7b44723 commit 3052c87
Show file tree
Hide file tree
Showing 15 changed files with 318 additions and 114 deletions.
60 changes: 29 additions & 31 deletions android/src/main/java/com/audiowaveform/AudioWaveformModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,10 @@ class AudioWaveformModule(context: ReactApplicationContext): ReactContextBaseJav
@ReactMethod
fun startPlayer(obj: ReadableMap, promise: Promise) {
val finishMode = obj.getInt(Constants.finishMode)
val key = obj.getString(Constants.playerKey)
val speed = obj.getDouble(Constants.speed)
if (key != null) {
audioPlayers[key]?.start(finishMode ?: 2, speed.toFloat(),promise)
} else {
promise.reject("startPlayer Error", "Player key can't be null")
}

val player = getPlayerOrReject(obj, promise, "startPlayer Error");
player?.start(finishMode ?: 2, speed.toFloat(),promise)
}

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

@ReactMethod
fun pausePlayer(obj: ReadableMap, promise: Promise) {
val key = obj.getString(Constants.playerKey)
if (key != null) {
audioPlayers[key]?.pause(promise)
} else {
promise.reject("pausePlayer Error", "Player key can't be null")
}
val player = getPlayerOrReject(obj, promise, "pausePlayer Error");
player?.pause(promise);
}

@ReactMethod
fun seekToPlayer(obj: ReadableMap, promise: Promise) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val progress = obj.getInt(Constants.progress)
val key = obj.getString(Constants.playerKey)
if (key != null) {
audioPlayers[key]?.seekToPosition(progress.toLong(), promise)
} else {
promise.reject("seekTo Error", "Player key can't be null")
}

val player = getPlayerOrReject(obj, promise, "seekTo Error");
player?.seekToPosition(progress.toLong(), promise)
} else {
Log.e(
Constants.LOG_TAG,
Expand All @@ -216,24 +206,18 @@ class AudioWaveformModule(context: ReactApplicationContext): ReactContextBaseJav
@ReactMethod
fun setVolume(obj: ReadableMap, promise: Promise) {
val volume = obj.getInt(Constants.volume)
val key = obj.getString(Constants.playerKey)
if (key != null) {
audioPlayers[key]?.setVolume(volume.toFloat(), promise)
} else {
promise.reject("setVolume error", "Player key can't be null")
}

val player = getPlayerOrReject(obj, promise, "setVolume Error");
player?.setVolume(volume.toFloat(), promise)
}

@ReactMethod
fun getDuration(obj: ReadableMap, promise: Promise) {
val key = obj.getString(Constants.playerKey)
val duration = obj.getInt(Constants.durationType)
val type = if (duration == 0) DurationType.Current else DurationType.Max
if (key != null) {
audioPlayers[key]?.getDuration(type, promise)
} else {
promise.reject("getDuration Error", "Player key can't be null")
}

val player = getPlayerOrReject(obj, promise, "getDuration Error");
player?.getDuration(type, promise)
}

@ReactMethod
Expand Down Expand Up @@ -316,7 +300,7 @@ class AudioWaveformModule(context: ReactApplicationContext): ReactContextBaseJav
}
}
override fun onReject(error: String?, message: String?) {
promise.reject(error, message)
promise.reject(error ?: "Error", message ?: "An error is thrown while decoding the audio file")
}
override fun onResolve(value: MutableList<MutableList<Float>>) {
promise.resolve(Arguments.fromList(value))
Expand Down Expand Up @@ -429,4 +413,18 @@ class AudioWaveformModule(context: ReactApplicationContext): ReactContextBaseJav
handler.removeCallbacks(emitLiveRecordValue)
}

private fun getPlayerOrReject(arguments: ReadableMap, promise: Promise, errorCode: String): AudioPlayer? {
val key = getPlayerKeyOrReject(arguments, promise, errorCode)
return audioPlayers[key] ?: run {
promise.reject(errorCode, "$errorCode: Player not in the list")
null
}
}

private fun getPlayerKeyOrReject(arguments: ReadableMap, promise: Promise, errorCode: String): String? {
return arguments.getString(Constants.playerKey) ?: run {
promise.reject(errorCode, "$errorCode: Player key can't be null")
null
}
}
}
40 changes: 36 additions & 4 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ PODS:
- hermes-engine/Pre-built (= 0.72.7)
- hermes-engine/Pre-built (0.72.7)
- libevent (2.1.12)
- libwebp (1.3.2):
- libwebp/demux (= 1.3.2)
- libwebp/mux (= 1.3.2)
- libwebp/sharpyuv (= 1.3.2)
- libwebp/webp (= 1.3.2)
- libwebp/demux (1.3.2):
- libwebp/webp
- libwebp/mux (1.3.2):
- libwebp/demux
- libwebp/sharpyuv (1.3.2)
- libwebp/webp (1.3.2):
- libwebp/sharpyuv
- OpenSSL-Universal (1.1.1100)
- RCT-Folly (2021.07.22.00):
- boost
Expand Down Expand Up @@ -378,7 +390,7 @@ PODS:
- react-native-audio-waveform (1.0.0):
- RCT-Folly (= 2021.07.22.00)
- React-Core
- react-native-safe-area-context (4.9.0):
- react-native-safe-area-context (4.11.0):
- React-Core
- React-NativeModulesApple (0.72.7):
- hermes-engine
Expand Down Expand Up @@ -492,11 +504,21 @@ PODS:
- React-perflogger (= 0.72.7)
- rn-fetch-blob (0.12.0):
- React-Core
- RNFastImage (8.6.3):
- React-Core
- SDWebImage (~> 5.11.1)
- SDWebImageWebPCoder (~> 0.8.4)
- RNFS (2.20.0):
- React-Core
- RNGestureHandler (2.14.0):
- RNGestureHandler (2.19.0):
- RCT-Folly (= 2021.07.22.00)
- React-Core
- SDWebImage (5.11.1):
- SDWebImage/Core (= 5.11.1)
- SDWebImage/Core (5.11.1)
- SDWebImageWebPCoder (0.8.5):
- libwebp (~> 1.0)
- SDWebImage/Core (~> 5.10)
- SocketRocket (0.6.1)
- Yoga (1.14.0)
- YogaKit (1.18.1):
Expand Down Expand Up @@ -568,6 +590,7 @@ DEPENDENCIES:
- React-utils (from `../node_modules/react-native/ReactCommon/react/utils`)
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
- rn-fetch-blob (from `../node_modules/rn-fetch-blob`)
- RNFastImage (from `../node_modules/react-native-fast-image`)
- RNFS (from `../node_modules/react-native-fs`)
- RNGestureHandler (from `../node_modules/react-native-gesture-handler`)
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)
Expand All @@ -585,7 +608,10 @@ SPEC REPOS:
- FlipperKit
- fmt
- libevent
- libwebp
- OpenSSL-Universal
- SDWebImage
- SDWebImageWebPCoder
- SocketRocket
- YogaKit

Expand Down Expand Up @@ -673,6 +699,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon"
rn-fetch-blob:
:path: "../node_modules/rn-fetch-blob"
RNFastImage:
:path: "../node_modules/react-native-fast-image"
RNFS:
:path: "../node_modules/react-native-fs"
RNGestureHandler:
Expand All @@ -698,6 +726,7 @@ SPEC CHECKSUMS:
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
hermes-engine: 9180d43df05c1ed658a87cc733dc3044cf90c00a
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
libwebp: 1786c9f4ff8a279e4dac1e8f385004d5fc253009
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1
RCTRequired: 83bca1c184feb4d2e51c72c8369b83d641443f95
Expand All @@ -715,7 +744,7 @@ SPEC CHECKSUMS:
React-jsinspector: 8baadae51f01d867c3921213a25ab78ab4fbcd91
React-logger: 8edc785c47c8686c7962199a307015e2ce9a0e4f
react-native-audio-waveform: 7cdb6e4963eeae907240396975b9c79713591758
react-native-safe-area-context: b97eb6f9e3b7f437806c2ce5983f479f8eb5de4b
react-native-safe-area-context: 851c62c48dce80ccaa5637b6aa5991a1bc36eca9
React-NativeModulesApple: b6868ee904013a7923128892ee4a032498a1024a
React-perflogger: 31ea61077185eb1428baf60c0db6e2886f141a5a
React-RCTActionSheet: 392090a3abc8992eb269ef0eaa561750588fc39d
Expand All @@ -734,8 +763,11 @@ SPEC CHECKSUMS:
React-utils: 56838edeaaf651220d1e53cd0b8934fb8ce68415
ReactCommon: 5f704096ccf7733b390f59043b6fa9cc180ee4f6
rn-fetch-blob: f065bb7ab7fb48dd002629f8bdcb0336602d3cba
RNFastImage: 5c9c9fed9c076e521b3f509fe79e790418a544e8
RNFS: 4ac0f0ea233904cb798630b3c077808c06931688
RNGestureHandler: 32a01c29ecc9bb0b5bf7bc0a33547f61b4dc2741
RNGestureHandler: 7ad14a6c7b491add489246611d324f10009083ac
SDWebImage: a7f831e1a65eb5e285e3fb046a23fcfbf08e696d
SDWebImageWebPCoder: 908b83b6adda48effe7667cd2b7f78c897e5111d
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
Yoga: 4c3aa327e4a6a23eeacd71f61c81df1bcdf677d5
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
Expand Down
1 change: 1 addition & 0 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"react": "18.2.0",
"react-native": "0.72.7",
"react-native-fast-image": "^8.6.3",
"react-native-fs": "^2.20.0",
"react-native-gesture-handler": "^2.13.4",
"react-native-safe-area-context": "^4.9.0",
Expand Down
Loading

0 comments on commit 3052c87

Please sign in to comment.