Skip to content

Commit b128b09

Browse files
Merge pull request #173 from SimformSolutionsPvtLtd/develop
Release v2.1.5
2 parents 52504cc + bc7b3eb commit b128b09

File tree

8 files changed

+58
-43
lines changed

8 files changed

+58
-43
lines changed

README.md

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -127,25 +127,26 @@ You can check out the full example at [Example](./example/src/App.tsx).
127127

128128
## Properties
129129

130-
| **Props** | **Default** | **Static Mode** | **Live Mode** | **Type** | **Description** |
131-
| ------------------------- | ----------- | --------------- | ------------- | ---------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
132-
| mode\* | - ||| 'live' or 'static' | Type of waveform. It can be either `static` for the resource file or `live` if you want to record audio |
133-
| ref\* | - ||| IWaveformRef | Type of ref provided to waveform component. If waveform mode is `static`, some methods from ref will throw error and same for `live`.<br> Check [IWaveformRef](#iwaveformref-methods) for more details about which methods these refs provides. |
134-
| path\* | - ||| string | Used for `static` type. It is the resource path of an audio source file. |
135-
| playbackSpeed | 1.0 ||| 1.0 / 1.5 / 2.0 | The playback speed of the audio player. Note: Currently playback speed only supports, Normal (1x) Faster(1.5x) and Fastest(2.0x), any value passed to playback speed greater than 2.0 will be automatically adjusted to normal playback speed |
136-
| candleSpace | 2 ||| number | Space between two candlesticks of waveform |
137-
| candleWidth | 5 ||| number | Width of single candlestick of waveform |
138-
| candleHeightScale | 3 ||| number | Scaling height of candlestick of waveform |
139-
| maxCandlesToRender | 300 ||| number | Number of candlestick in waveform |
140-
| containerStyle | - ||| `StyleProp<ViewStyle>` | style of the container |
141-
| waveColor | #545454 ||| string | color of candlestick of waveform |
142-
| scrubColor | #7b7b7b ||| string | color of candlestick of waveform which has played |
143-
| onPlayerStateChange | - ||| ( playerState : PlayerState ) => void | callback function, which returns player state whenever player state changes. |
144-
| onPanStateChange | - ||| ( panMoving : boolean ) => void | callback function which returns boolean indicating whether audio seeking is active or not. |
145-
| onRecorderStateChange | - ||| ( recorderState : RecorderState ) => void | callback function which returns the recorder state whenever the recorder state changes. Check RecorderState for more details |
146-
| onCurrentProgressChange | - ||| ( currentProgress : number, songDuration: number ) => void | callback function, which returns current progress of audio and total song duration. |
147-
| onChangeWaveformLoadState | - ||| ( state : boolean ) => void | callback function which returns the loading state of waveform candlestick. |
148-
| onError | - ||| ( error : Error ) => void | callback function which returns the error for static audio waveform |
130+
| **Props** | **Default** | **Static Mode** | **Live Mode** | **Type** | **Description** |
131+
| ------------------------------ | ----------- | --------------- | ------------- | ---------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
132+
| mode\* | - ||| 'live' or 'static' | Type of waveform. It can be either `static` for the resource file or `live` if you want to record audio |
133+
| ref\* | - ||| IWaveformRef | Type of ref provided to waveform component. If waveform mode is `static`, some methods from ref will throw error and same for `live`.<br> Check [IWaveformRef](#iwaveformref-methods) for more details about which methods these refs provides. |
134+
| path\* | - ||| string | Used for `static` type. It is the resource path of an audio source file. |
135+
| playbackSpeed | 1.0 ||| 1.0 / 1.5 / 2.0 | The playback speed of the audio player. Note: Currently playback speed only supports, Normal (1x) Faster(1.5x) and Fastest(2.0x), any value passed to playback speed greater than 2.0 will be automatically adjusted to normal playback speed |
136+
| candleSpace | 2 ||| number | Space between two candlesticks of waveform |
137+
| candleWidth | 5 ||| number | Width of single candlestick of waveform |
138+
| candleHeightScale | 3 ||| number | Scaling height of candlestick of waveform |
139+
| maxCandlesToRender | 300 ||| number | Number of candlestick in waveform |
140+
| containerStyle | - ||| `StyleProp<ViewStyle>` | style of the container |
141+
| waveColor | #545454 ||| string | color of candlestick of waveform |
142+
| scrubColor | #7b7b7b ||| string | color of candlestick of waveform which has played |
143+
| onPlayerStateChange | - ||| ( playerState : PlayerState ) => void | callback function, which returns player state whenever player state changes. |
144+
| onPanStateChange | - ||| ( panMoving : boolean ) => void | callback function which returns boolean indicating whether audio seeking is active or not. |
145+
| onRecorderStateChange | - ||| ( recorderState : RecorderState ) => void | callback function which returns the recorder state whenever the recorder state changes. Check RecorderState for more details |
146+
| onCurrentProgressChange | - ||| ( currentProgress : number, songDuration: number ) => void | callback function, which returns current progress of audio and total song duration. |
147+
| onChangeWaveformLoadState | - ||| ( state : boolean ) => void | callback function which returns the loading state of waveform candlestick. |
148+
| onError | - ||| ( error : Error ) => void | callback function which returns the error for static audio waveform |
149+
| showsHorizontalScrollIndicator | false ||| boolean | whether to show scroll indicator when live waveform is being recorded and total width is more than parent view width |
149150

150151
##### Know more about [ViewStyle](https://reactnative.dev/docs/view-style-props), [PlayerState](#playerstate), and [RecorderState](#recorderstate)
151152

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

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.media.AudioManager
77
import android.net.Uri
88
import android.os.Build
99
import android.os.CountDownTimer
10+
import android.os.Handler
1011
import com.facebook.react.bridge.Arguments
1112
import com.facebook.react.bridge.Promise
1213
import com.facebook.react.bridge.ReactApplicationContext
@@ -54,33 +55,41 @@ class AudioPlayer(
5455
private fun handleAudioFocusChange(focusChange: Int) {
5556
when (focusChange) {
5657
AudioManager.AUDIOFOCUS_GAIN -> {
57-
// Audio focus granted; resume playback if necessary
58-
if (!player.isPlaying) {
59-
player.play()
60-
}
61-
player.volume = 1.0f // Restore full volume
58+
player.applicationLooper.let { looper -> Handler(looper).post {
59+
// Audio focus granted; resume playback if necessary
60+
if (!player.isPlaying) {
61+
player.play()
62+
}
63+
player.volume = 1.0f // Restore full volume
64+
}}
6265
}
6366
AudioManager.AUDIOFOCUS_LOSS -> {
64-
// Permanent loss of audio focus; pause playback
65-
if (player.isPlaying) {
66-
val args: WritableMap = Arguments.createMap()
67-
stopListening()
68-
player.pause()
69-
abandonAudioFocus()
70-
args.putInt(Constants.finishType, 1)
71-
args.putString(Constants.playerKey, key)
72-
appContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)?.emit("onDidFinishPlayingAudio", args)
73-
}
67+
player.applicationLooper.let { looper -> Handler(looper).post {
68+
// Permanent loss of audio focus; pause playback
69+
if (player.isPlaying) {
70+
val args: WritableMap = Arguments.createMap()
71+
stopListening()
72+
player.pause()
73+
abandonAudioFocus()
74+
args.putInt(Constants.finishType, 1)
75+
args.putString(Constants.playerKey, key)
76+
appContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)?.emit("onDidFinishPlayingAudio", args)
77+
}
78+
}}
7479
}
7580
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT -> {
76-
// Temporary loss of audio focus; pause playback
77-
if (player.isPlaying) {
78-
player.pause()
79-
}
81+
player.applicationLooper.let { looper -> Handler(looper).post {
82+
// Temporary loss of audio focus; pause playback
83+
if (player.isPlaying) {
84+
player.pause()
85+
}
86+
}}
8087
}
8188
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK -> {
82-
// Temporarily loss of audio focus; but can continue playing at a lower volume.
83-
player.volume = 0.2f
89+
player.applicationLooper.let { looper -> Handler(looper).post {
90+
// Temporarily loss of audio focus; but can continue playing at a lower volume.
91+
player.volume = 0.2f
92+
}}
8493
}
8594
}
8695
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class AudioWaveformModule(context: ReactApplicationContext): ReactContextBaseJav
131131
) {
132132
if(audioPlayers.filter { it.value?.isHoldingAudioTrack() == true }.count() >= MAX_NUMBER_OF_AUDIO_PLAYER) {
133133
promise.reject(Constants.LOG_TAG, "Too many players have been initialized. Please stop some players before continuing")
134+
return
134135
}
135136

136137
val path = obj.getString(Constants.path)

example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ PODS:
12221222
- React-jsiexecutor
12231223
- React-RCTFBReactNativeSpec
12241224
- ReactCommon/turbomodule/core
1225-
- react-native-audio-waveform (2.1.3):
1225+
- react-native-audio-waveform (2.1.5):
12261226
- DoubleConversion
12271227
- glog
12281228
- hermes-engine
@@ -1904,7 +1904,7 @@ SPEC CHECKSUMS:
19041904
React-logger: 9a0c4e1e41cd640ac49d69aacadab783f7e0096b
19051905
React-Mapbuffer: 6993c785c22a170c02489bc78ed207814cbd700f
19061906
React-microtasksnativemodule: 19230cd0933df6f6dc1336c9a9edc382d62638ae
1907-
react-native-audio-waveform: 37744a7dfd0ae7b7dbab14cfa59c1dbe2cb0b20c
1907+
react-native-audio-waveform: 76e2a504df52d7b124699cc35fec3491303577a3
19081908
react-native-safe-area-context: 9c33120e9eac7741a5364cc2d9f74665049b76b3
19091909
React-nativeconfig: cd0fbb40987a9658c24dab5812c14e5522a64929
19101910
React-NativeModulesApple: 45187d13c68d47250a7416b18ff082c7cc07bff7

0 commit comments

Comments
 (0)