Skip to content

Commit 52504cc

Browse files
Merge pull request #161 from SimformSolutionsPvtLtd/develop
Release v2.1.4
2 parents 2c3282e + eb3845d commit 52504cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2205
-1394
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,33 @@ resumePlayer(): Promise<boolean>
191191

192192
It returns a boolean indicating whether playback is resumed again.
193193

194+
#### stopAllPlayers()
195+
196+
```ts
197+
stopAllPlayers(): Promise<boolean>
198+
```
199+
200+
Stops all the players at once and frees their native resources. Useful on unmount!
201+
It returns a boolean indicating that all players were stopped.
202+
203+
#### stopAllWaveFormExtractors()
204+
205+
```ts
206+
stopAllWaveFormExtractors(): Promise<boolean>
207+
```
208+
209+
Stops all the extractors used to build the audio waveform and frees its native resource. Useful on unmount!
210+
It returns a boolean indicating that all extractors were stopped.
211+
212+
#### stopPlayersAndExtractors()
213+
214+
```ts
215+
stopPlayersAndExtractors(): Promise<[boolean, boolean]>
216+
```
217+
218+
Combined the `stopAllWaveFormExtractors` and `stopAllPlayers` in one call to free up the maximum possible resources. Very useful on unmount!
219+
It returns an array of two booleans indicating if all players and all waveform extractors were stopped.
220+
194221
#### For Live mode
195222

196223
#### startRecord()

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ class AudioPlayer(
223223
if (requestAudioFocus()) {
224224
player.playWhenReady = true
225225
player.play()
226+
emitCurrentDuration()
226227
promise.resolve(true)
227228
startListening(promise)}
228229
else {
@@ -235,6 +236,7 @@ class AudioPlayer(
235236

236237
fun stop() {
237238
stopListening()
239+
emitCurrentDuration()
238240
if (playerListener != null) {
239241
player.removeListener(playerListener!!)
240242
}
@@ -248,6 +250,7 @@ class AudioPlayer(
248250
try {
249251
stopListening()
250252
player.pause()
253+
emitCurrentDuration()
251254
abandonAudioFocus()
252255
promise?.resolve(true)
253256
} catch (e: Exception) {
@@ -273,17 +276,22 @@ class AudioPlayer(
273276
return validateAndSetPlaybackSpeed(player, speed)
274277
}
275278

279+
280+
fun emitCurrentDuration() {
281+
val currentPosition = player.currentPosition.toString()
282+
val args: WritableMap = Arguments.createMap()
283+
args.putString(Constants.currentDuration, currentPosition)
284+
args.putString(Constants.playerKey, key)
285+
if (isComponentMounted) {
286+
appContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)?.emit("onCurrentDuration", args)
287+
}
288+
}
289+
276290
private fun startListening(promise: Promise) {
277291
try {
278292
audioPlaybackListener = object : CountDownTimer(player.duration, UpdateFrequency.Low.value) {
279293
override fun onTick(millisUntilFinished: Long) {
280-
val currentPosition = player.currentPosition.toString()
281-
val args: WritableMap = Arguments.createMap()
282-
args.putString(Constants.currentDuration, currentPosition)
283-
args.putString(Constants.playerKey, key)
284-
if (isComponentMounted) {
285-
appContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)?.emit("onCurrentDuration", args)
286-
}
294+
emitCurrentDuration()
287295
}
288296
override fun onFinish() {}
289297
}.start()

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import com.facebook.react.modules.core.DeviceEventManagerModule
1717
import java.io.File
1818
import java.io.IOException
1919
import java.text.SimpleDateFormat
20+
import java.util.Collections
2021
import java.util.Date
2122
import java.util.Locale
2223

@@ -234,11 +235,28 @@ class AudioWaveformModule(context: ReactApplicationContext): ReactContextBaseJav
234235

235236
@ReactMethod
236237
fun stopAllPlayers(promise: Promise) {
237-
for ((key, _) in audioPlayers) {
238-
audioPlayers[key]?.stop()
239-
audioPlayers[key] = null
238+
try {
239+
audioPlayers.values.forEach{
240+
player -> player?.stop()
241+
}
242+
audioPlayers.clear()
243+
promise.resolve(true)
244+
} catch (err: Exception) {
245+
promise.reject("stopAllPlayers Error", "Error while stopping all players")
246+
}
247+
}
248+
249+
@ReactMethod
250+
fun stopAllWaveFormExtractors(promise: Promise) {
251+
try {
252+
extractors.values.forEach{
253+
extractor -> extractor?.forceStop()
254+
}
255+
extractors.clear()
256+
promise.resolve(true)
257+
} catch (err: Exception) {
258+
promise.reject("stopAllExtractors Error", "Error while stopping all extractors")
240259
}
241-
promise.resolve(true)
242260
}
243261

244262
@ReactMethod
@@ -305,6 +323,9 @@ class AudioWaveformModule(context: ReactApplicationContext): ReactContextBaseJav
305323
override fun onResolve(value: MutableList<MutableList<Float>>) {
306324
promise.resolve(Arguments.fromList(value))
307325
}
326+
override fun onForceStop() {
327+
promise.resolve(Arguments.fromList(mutableListOf(emptyList<Float>())))
328+
}
308329
}
309330
)
310331
extractors[playerKey]?.startDecode();

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule
1212
import com.facebook.react.bridge.WritableMap
1313
import com.facebook.react.modules.core.DeviceEventManagerModule
1414
import java.nio.ByteBuffer
15-
import java.util.concurrent.CountDownLatch
1615
import kotlin.math.pow
1716
import kotlin.math.sqrt
1817
import java.io.File
@@ -32,7 +31,6 @@ class WaveformExtractor(
3231

3332
@Volatile
3433
private var inProgress = false
35-
private val finishCount = CountDownLatch(1)
3634
private var inputEof = false
3735
private var sampleRate = 0
3836
private var channels = 1
@@ -122,7 +120,6 @@ class WaveformExtractor(
122120
Constants.LOG_TAG + " " + e.message,
123121
"An error is thrown while decoding the audio file"
124122
)
125-
finishCount.countDown()
126123
}
127124

128125
override fun onOutputBufferAvailable(
@@ -256,13 +253,18 @@ class WaveformExtractor(
256253
}
257254
}
258255

256+
fun forceStop() {
257+
stop()
258+
// When stopped by outside we must notify to resolved the hanging promises
259+
extractorCallBack.onForceStop()
260+
}
261+
259262
private fun stop() {
260263
if (!inProgress) return
261264
inProgress = false
262265
decoder?.stop()
263266
decoder?.release()
264267
extractor?.release()
265-
finishCount.countDown()
266268
}
267269
}
268270

@@ -272,4 +274,5 @@ interface ExtractorCallBack {
272274
fun onProgress(value: Float)
273275
fun onReject(error: String?, message: String?)
274276
fun onResolve(value: MutableList<MutableList<Float>>)
277+
fun onForceStop()
275278
}

example/.gitignore

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ DerivedData
2020
*.hmap
2121
*.ipa
2222
*.xcuserstate
23-
ios/.xcode.env.local
23+
**/.xcode.env.local
2424
ios/link-assets-manifest.json
2525

2626
# Android/IntelliJ
@@ -33,6 +33,8 @@ local.properties
3333
*.hprof
3434
.cxx/
3535
android/link-assets-manifest.json
36+
*.keystore
37+
!debug.keystore
3638

3739
# node.js
3840
#
@@ -63,5 +65,19 @@ buck-out/
6365
*.jsbundle
6466

6567
# Ruby / CocoaPods
66-
/ios/Pods/
68+
**/Pods/
6769
/vendor/bundle/
70+
71+
# Temporary files created by Metro to check the health of the file watcher
72+
.metro-health-check*
73+
74+
# testing
75+
/coverage
76+
77+
# Yarn
78+
.yarn/*
79+
!.yarn/patches
80+
!.yarn/plugins
81+
!.yarn/releases
82+
!.yarn/sdks
83+
!.yarn/versions

example/.node-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

example/.ruby-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

example/Gemfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@ source 'https://rubygems.org'
33
# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
44
ruby ">= 2.6.10"
55

6-
gem 'cocoapods', '~> 1.13'
7-
gem 'activesupport', '>= 6.1.7.3', '< 7.1.0'
6+
# Exclude problematic versions of cocoapods and activesupport that causes build failures.
7+
gem 'cocoapods', '>= 1.13', '!= 1.15.0', '!= 1.15.1'
8+
gem 'activesupport', '>= 6.1.7.5', '!= 7.1.0'
9+
gem 'xcodeproj', '< 1.26.0'
10+
gem 'concurrent-ruby', '< 1.3.4'

example/android/app/build.gradle

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
apply plugin: "com.android.application"
2+
apply plugin: "org.jetbrains.kotlin.android"
23
apply plugin: "com.facebook.react"
34

45
/**
@@ -7,14 +8,14 @@ apply plugin: "com.facebook.react"
78
*/
89
react {
910
/* Folders */
10-
// The root of your project, i.e. where "package.json" lives. Default is '..'
11-
// root = file("../")
12-
// The folder where the react-native NPM package is. Default is ../node_modules/react-native
13-
// reactNativeDir = file("../node_modules/react-native")
14-
// The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen
15-
// codegenDir = file("../node_modules/@react-native/codegen")
16-
// The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js
17-
// cliFile = file("../node_modules/react-native/cli.js")
11+
// The root of your project, i.e. where "package.json" lives. Default is '../..'
12+
// root = file("../../")
13+
// The folder where the react-native NPM package is. Default is ../../node_modules/react-native
14+
// reactNativeDir = file("../../node_modules/react-native")
15+
// The folder where the react-native Codegen package is. Default is ../../node_modules/@react-native/codegen
16+
// codegenDir = file("../../node_modules/@react-native/codegen")
17+
// The cli.js file which is the React Native CLI entrypoint. Default is ../../node_modules/react-native/cli.js
18+
// cliFile = file("../../node_modules/react-native/cli.js")
1819

1920
/* Variants */
2021
// The list of variants to that are debuggable. For those we're going to
@@ -48,6 +49,9 @@ react {
4849
//
4950
// The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
5051
// hermesFlags = ["-O", "-output-source-map"]
52+
53+
/* Autolinking */
54+
autolinkLibrariesWithApp()
5155
}
5256

5357
/**
@@ -70,8 +74,8 @@ def jscFlavor = 'org.webkit:android-jsc:+'
7074

7175
android {
7276
ndkVersion rootProject.ext.ndkVersion
73-
74-
compileSdkVersion rootProject.ext.compileSdkVersion
77+
buildToolsVersion rootProject.ext.buildToolsVersion
78+
compileSdk rootProject.ext.compileSdkVersion
7579

7680
namespace "com.audiowaveformexample"
7781
defaultConfig {
@@ -106,19 +110,10 @@ android {
106110
dependencies {
107111
// The version of react-native is set by the React Native Gradle Plugin
108112
implementation("com.facebook.react:react-android")
109-
implementation 'com.facebook.fresco:animated-gif:2.5.0'
110113

111-
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
112-
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
113-
exclude group:'com.squareup.okhttp3', module:'okhttp'
114-
}
115-
116-
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")
117114
if (hermesEnabled.toBoolean()) {
118115
implementation("com.facebook.react:hermes-android")
119116
} else {
120117
implementation jscFlavor
121118
}
122119
}
123-
124-
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

example/android/app/src/debug/AndroidManifest.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools">
44

5-
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
6-
75
<application
86
android:usesCleartextTraffic="true"
97
tools:targetApi="28"
10-
tools:ignore="GoogleAppIndexingWarning">
11-
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="false" />
12-
</application>
8+
tools:ignore="GoogleAppIndexingWarning"/>
139
</manifest>

0 commit comments

Comments
 (0)