Skip to content

Commit 463845b

Browse files
committed
fix: seeking in voice recording regression
1 parent 4ff7714 commit 463845b

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

package/src/components/MessageInput/components/AudioRecorder/AudioRecordingPreview.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import dayjs from 'dayjs';
55

66
import { useMessageInputContext } from '../../../../contexts/messageInputContext/MessageInputContext';
77
import { useTheme } from '../../../../contexts/themeContext/ThemeContext';
8+
import { useStableCallback } from '../../../../hooks';
89
import { useAudioPlayer } from '../../../../hooks/useAudioPlayer';
910
import { useStateStore } from '../../../../hooks/useStateStore';
1011

@@ -100,6 +101,16 @@ export const AudioRecordingPreview = () => {
100101
[duration, position],
101102
);
102103

104+
const dragStart = useStableCallback(() => {
105+
audioPlayer.pause();
106+
});
107+
108+
const dragEnd = useStableCallback(async (currentProgress: number) => {
109+
const positionInSeconds = (currentProgress * duration) / ONE_SECOND_IN_MILLISECONDS;
110+
await audioPlayer.seek(positionInSeconds);
111+
audioPlayer.play();
112+
});
113+
103114
return (
104115
<View style={[styles.container, container]}>
105116
<View style={[styles.infoContainer, infoContainer]}>
@@ -123,7 +134,13 @@ export const AudioRecordingPreview = () => {
123134
</View>
124135
<View style={[styles.progressBar, progressBar]}>
125136
{/* Since the progress is in range 0-1 we convert it in terms of 100% */}
126-
<WaveProgressBar progress={progress} waveformData={waveformData} />
137+
<WaveProgressBar
138+
isPlaying={isPlaying}
139+
progress={progress}
140+
waveformData={waveformData}
141+
onStartDrag={dragStart}
142+
onEndDrag={dragEnd}
143+
/>
127144
</View>
128145
</View>
129146
);

package/src/components/ProgressControl/WaveProgressBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export const WaveProgressBar = React.memo(
107107
}
108108
})
109109
.onUpdate((event) => {
110-
const newProgress = Math.max(0, Math.min(event.x / fullWidth, 1));
110+
const newProgress = Math.max(0, Math.min((state.value + event.x) / fullWidth, 1));
111111
state.value = newProgress;
112112
waveFormNumberFromProgress(newProgress);
113113
})

package/src/state-store/audio-player.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,10 @@ export class AudioPlayer {
310310

311311
async seek(positionInSeconds: number) {
312312
if (this.previewVoiceRecording) {
313-
this.position = positionInSeconds;
313+
const positionInMillis = positionInSeconds * 1000;
314+
this.position = positionInMillis;
314315
if (NativeHandlers.Audio?.seekToPlayer) {
315-
NativeHandlers.Audio.seekToPlayer(positionInSeconds * 1000);
316+
await NativeHandlers.Audio.seekToPlayer(positionInMillis);
316317
}
317318
return;
318319
}

0 commit comments

Comments
 (0)