File tree Expand file tree Collapse file tree 3 files changed +22
-4
lines changed
MessageInput/components/AudioRecorder Expand file tree Collapse file tree 3 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import dayjs from 'dayjs';
55
66import { useMessageInputContext } from '../../../../contexts/messageInputContext/MessageInputContext' ;
77import { useTheme } from '../../../../contexts/themeContext/ThemeContext' ;
8+ import { useStableCallback } from '../../../../hooks' ;
89import { useAudioPlayer } from '../../../../hooks/useAudioPlayer' ;
910import { 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 ) ;
Original file line number Diff line number Diff 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 } )
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments