Skip to content

Commit ac4e82a

Browse files
committed
fix: add onRecordingProgressChange callback to be able to be used by all consumers
1 parent 0d5372e commit ac4e82a

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ You can check out the full example at [Example](./example/src/App.tsx).
145145
| onRecorderStateChange | - ||| ( recorderState : RecorderState ) => void | callback function which returns the recorder state whenever the recorder state changes. Check RecorderState for more details |
146146
| onCurrentProgressChange | - ||| ( currentProgress : number, songDuration: number ) => void | callback function, which returns current progress of audio and total song duration. |
147147
| onChangeWaveformLoadState | - ||| ( state : boolean ) => void | callback function which returns the loading state of waveform candlestick. |
148+
| onRecordingProgressChange | - ||| ( currentProgress : number ) => void | callback function which returns current progress of recording audio. |
148149
| onError | - ||| ( error : Error ) => void | callback function which returns the error for static audio waveform |
149150
| showsHorizontalScrollIndicator | false ||| boolean | whether to show scroll indicator when live waveform is being recorded and total width is more than parent view width |
150151

example/src/App.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ const LivePlayerComponent = ({
251251
candleWidth={4}
252252
waveColor={Colors.pink}
253253
onRecorderStateChange={setRecorderState}
254+
onRecordingProgressChange={currentProgress => {
255+
console.log(`currentProgress ${currentProgress}`);
256+
}}
254257
/>
255258
<Pressable
256259
onPress={handleRecorderAction}

src/components/Waveform/Waveform.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export const Waveform = forwardRef<IWaveformRef, IWaveform>((props, ref) => {
6161
onPanStateChange = () => {},
6262
onError = (_error: Error) => {},
6363
onCurrentProgressChange = () => {},
64+
onRecordingProgressChange = () => {},
6465
candleHeightScale = 3,
6566
onChangeWaveformLoadState = (_state: boolean) => {},
6667
showsHorizontalScrollIndicator = false,
@@ -504,6 +505,9 @@ export const Waveform = forwardRef<IWaveformRef, IWaveform>((props, ref) => {
504505
const traceRecorderWaveformValue = onCurrentRecordingWaveformData(
505506
result => {
506507
if (mode === 'live') {
508+
if (!isNil(onRecordingProgressChange)) {
509+
(onRecordingProgressChange as Function)(result.progress);
510+
}
507511
if (!isNil(result.currentDecibel)) {
508512
setWaveform((previousWaveform: number[]) => {
509513
// Add the new decibel to the waveform

src/components/Waveform/WaveformTypes.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export interface StaticWaveform extends BaseWaveform {
2828
songDuration: number
2929
) => void;
3030
onChangeWaveformLoadState?: (state: boolean) => void;
31+
onRecordingProgressChange?: (
32+
currentProgress: number,
33+
) => void;
3134
playbackSpeed?: PlaybackSpeedType;
3235
}
3336

0 commit comments

Comments
 (0)