Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions android/src/main/java/com/audiowaveform/AudioWaveformModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,19 @@ class AudioWaveformModule(context: ReactApplicationContext): ReactContextBaseJav
player -> player?.stop()
}
audioPlayers.clear()
promise.resolve(true)

if (audioPlayers.isEmpty()) {
val args: WritableMap = Arguments.createMap()
args.putBoolean("clearedPlayers", true)

reactApplicationContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
?.emit(Constants.onResetAllWaveforms, args)

promise.resolve(true)
} else {
promise.reject("REMOVE_FAILED", "Failed to clear all audio players")
}
} catch (err: Exception) {
promise.reject("stopAllPlayers Error", "Error while stopping all players")
}
Expand All @@ -249,7 +261,18 @@ class AudioWaveformModule(context: ReactApplicationContext): ReactContextBaseJav
extractor -> extractor?.forceStop()
}
extractors.clear()
promise.resolve(true)
if (audioPlayers.isEmpty()) {
val args: WritableMap = Arguments.createMap()
args.putBoolean("clearedExtractors", true)

reactApplicationContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
?.emit(Constants.onResetAllWaveforms, args)

promise.resolve(true)
} else {
promise.reject("REMOVE_FAILED", "Failed to clear all audio players")
}
} catch (err: Exception) {
promise.reject("stopAllExtractors Error", "Error while stopping all extractors")
}
Expand Down
1 change: 1 addition & 0 deletions android/src/main/java/com/audiowaveform/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ object Constants {
const val bitRate = "bitRate"
const val sampleRate = "sampleRate"
const val speed = "speed"
const val onResetAllWaveforms = "onResetAllWaveforms"
}

enum class FinishMode(val value:Int) {
Expand Down
22 changes: 11 additions & 11 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ PODS:
- React-jsiexecutor
- React-RCTFBReactNativeSpec
- ReactCommon/turbomodule/core
- react-native-audio-waveform (2.1.5):
- react-native-audio-waveform (2.1.6):
- DoubleConversion
- glog
- hermes-engine
Expand All @@ -1243,7 +1243,7 @@ PODS:
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- react-native-safe-area-context (5.2.0):
- react-native-safe-area-context (5.6.1):
- DoubleConversion
- glog
- hermes-engine
Expand All @@ -1256,8 +1256,8 @@ PODS:
- React-featureflags
- React-graphics
- React-ImageManager
- react-native-safe-area-context/common (= 5.2.0)
- react-native-safe-area-context/fabric (= 5.2.0)
- react-native-safe-area-context/common (= 5.6.1)
- react-native-safe-area-context/fabric (= 5.6.1)
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
Expand All @@ -1266,7 +1266,7 @@ PODS:
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- react-native-safe-area-context/common (5.2.0):
- react-native-safe-area-context/common (5.6.1):
- DoubleConversion
- glog
- hermes-engine
Expand All @@ -1287,7 +1287,7 @@ PODS:
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- react-native-safe-area-context/fabric (5.2.0):
- react-native-safe-area-context/fabric (5.6.1):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -1606,7 +1606,7 @@ PODS:
- SDWebImageWebPCoder (~> 0.8.4)
- RNFS (2.20.0):
- React-Core
- RNGestureHandler (2.23.1):
- RNGestureHandler (2.25.0):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -1904,8 +1904,8 @@ SPEC CHECKSUMS:
React-logger: 9a0c4e1e41cd640ac49d69aacadab783f7e0096b
React-Mapbuffer: 6993c785c22a170c02489bc78ed207814cbd700f
React-microtasksnativemodule: 19230cd0933df6f6dc1336c9a9edc382d62638ae
react-native-audio-waveform: 76e2a504df52d7b124699cc35fec3491303577a3
react-native-safe-area-context: 9c33120e9eac7741a5364cc2d9f74665049b76b3
react-native-audio-waveform: c253cf552518a830fb7876c9140f43c6c7415f6c
react-native-safe-area-context: ad7b31de8373577e003e700340b746fd5645b12c
React-nativeconfig: cd0fbb40987a9658c24dab5812c14e5522a64929
React-NativeModulesApple: 45187d13c68d47250a7416b18ff082c7cc07bff7
React-perflogger: 15a7bcb6c46eae8a981f7add8c9f4172e2372324
Expand Down Expand Up @@ -1938,12 +1938,12 @@ SPEC CHECKSUMS:
rn-fetch-blob: f065bb7ab7fb48dd002629f8bdcb0336602d3cba
RNFastImage: 5c9c9fed9c076e521b3f509fe79e790418a544e8
RNFS: 4ac0f0ea233904cb798630b3c077808c06931688
RNGestureHandler: 9ae308f1850d9c296a1230db9d1b52858911916b
RNGestureHandler: 66e593addd8952725107cfaa4f5e3378e946b541
SDWebImage: a7f831e1a65eb5e285e3fb046a23fcfbf08e696d
SDWebImageWebPCoder: 908b83b6adda48effe7667cd2b7f78c897e5111d
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
Yoga: 78d74e245ed67bb94275a1316cdc170b9b7fe884

PODFILE CHECKSUM: 6f704d99bbe3053bd858eef7cb4caed0084ae50b

COCOAPODS: 1.16.2
COCOAPODS: 1.14.3
16 changes: 14 additions & 2 deletions ios/AudioWaveform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,27 @@ class AudioWaveform: RCTEventEmitter {
audioPlayers[playerKey]?.stopPlayer()
}
audioPlayers.removeAll()
resolve(true)

if audioPlayers.isEmpty {
EventEmitter.sharedInstance.dispatch(name: Constants.onResetAllWaveforms, body: ["clearedPlayers": true])
resolve(true)
} else {
reject("REMOVE_FAILED", "Failed to clear all audio players", nil)
}
}

@objc func stopAllWaveFormExtractors(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
for (extractorKey,_) in extractors{
extractors[extractorKey]?.cancel()
}
extractors.removeAll()
resolve(true)

if extractors.isEmpty {
EventEmitter.sharedInstance.dispatch(name: Constants.onResetAllWaveforms, body: ["clearedExtractors": true])
resolve(true)
} else {
reject("REMOVE_FAILED", "Failed to clear all extractors", nil)
}
}


Expand Down
2 changes: 1 addition & 1 deletion ios/EventEmitter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class EventEmitter {

/// All Events which must be support by React Native.
lazy var allEvents: [String] = {
var allEventNames: [String] = ["onDidFinishPlayingAudio", "onCurrentDuration", "onCurrentExtractedWaveformData", "onCurrentRecordingWaveformData"]
var allEventNames: [String] = ["onDidFinishPlayingAudio", "onCurrentDuration", "onCurrentExtractedWaveformData", "onCurrentRecordingWaveformData", "onResetAllWaveforms"]

// Append all events here

Expand Down
1 change: 1 addition & 0 deletions ios/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ struct Constants {
static let useLegacyNormalization = "useLegacyNormalization"
static let updateFrequency = "updateFrequency"
static let onGetAudioBuffers = "onGetAudioBuffers"
static let onResetAllWaveforms = "onResetAllWaveforms"
}

enum FinishMode : Int{
Expand Down
14 changes: 14 additions & 0 deletions src/components/Waveform/Waveform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const Waveform = forwardRef<IWaveformRef, IWaveform>((props, ref) => {
onCurrentRecordingWaveformData,
setPlaybackSpeed,
markPlayerAsUnmounted,
onResetAllWaveforms,
} = useAudioPlayer();

const { startRecording, stopRecording, pauseRecording, resumeRecording } =
Expand Down Expand Up @@ -533,6 +534,19 @@ export const Waveform = forwardRef<IWaveformRef, IWaveform>((props, ref) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
const traceAllWaveformReset = onResetAllWaveforms(() => {
// This component (and maybe others) should reset progress to 0
if (playerState !== PlayerState.stopped || currentProgress !== 0) {
stopPlayerAction();
}
});
return () => {
traceAllWaveformReset.remove();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [playerState, currentProgress]);

useEffect(() => {
if (!isNil(onPlayerStateChange)) {
(onPlayerStateChange as Function)(playerState);
Expand Down
1 change: 1 addition & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export enum NativeEvents {
onCurrentDuration = 'onCurrentDuration',
onCurrentExtractedWaveformData = 'onCurrentExtractedWaveformData',
onCurrentRecordingWaveformData = 'onCurrentRecordingWaveformData',
onResetAllWaveforms = 'onResetAllWaveforms',
}

export enum PermissionStatus {
Expand Down
8 changes: 8 additions & 0 deletions src/hooks/useAudioPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ export const useAudioPlayer = () => {
AudioWaveform.markPlayerAsUnmounted();
};

const onResetAllWaveforms = (
callback: (result: IOnCurrentRecordingWaveForm) => void
) =>
audioPlayerEmitter.addListener(NativeEvents.onResetAllWaveforms, result =>
callback(result)
);

return {
extractWaveformData,
pausePlayer,
Expand All @@ -104,5 +111,6 @@ export const useAudioPlayer = () => {
markPlayerAsUnmounted,
stopAllWaveFormExtractors,
stopPlayersAndExtractors,
onResetAllWaveforms,
};
};