@@ -16,7 +16,7 @@ import {
1616 VideoProgressData ,
1717 VideoSeekResponse ,
1818} from '../../native' ;
19- import type { FileUpload } from '../../types/types' ;
19+ import { FileTypes , type FileUpload } from '../../types/types' ;
2020import { getTrimmedAttachmentTitle } from '../../utils/getTrimmedAttachmentTitle' ;
2121import { ProgressControl } from '../ProgressControl/ProgressControl' ;
2222import { WaveProgressBar } from '../ProgressControl/WaveProgressBar' ;
@@ -52,19 +52,34 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
5252 } = props ;
5353 const { changeAudioSpeed, pauseAudio, playAudio, seekAudio } = useAudioPlayer ( { soundRef } ) ;
5454 const isExpoCLI = SDK === 'stream-chat-expo' ;
55+ const isVoiceRecording = item . type === FileTypes . VoiceRecording ;
5556
5657 /** This is for Native CLI Apps */
5758 const handleLoad = ( payload : VideoPayloadData ) => {
58- onLoad ( item . id , item . duration || payload . duration ) ;
59+ // The duration given by the rn-video is not same as the one of the voice recording, so we take the actual duration for voice recording.
60+ if ( isVoiceRecording && item . duration ) {
61+ onLoad ( item . id , item . duration ) ;
62+ } else {
63+ onLoad ( item . id , item . duration || payload . duration ) ;
64+ }
5965 } ;
6066
6167 /** This is for Native CLI Apps */
6268 const handleProgress = ( data : VideoProgressData ) => {
6369 const { currentTime, seekableDuration } = data ;
64- if ( currentTime < seekableDuration && ! audioFinished ) {
65- onProgress ( item . id , currentTime / seekableDuration ) ;
70+ // The duration given by the rn-video is not same as the one of the voice recording, so we take the actual duration for voice recording.
71+ if ( isVoiceRecording && item . duration ) {
72+ if ( currentTime < item . duration && ! audioFinished ) {
73+ onProgress ( item . id , currentTime / item . duration ) ;
74+ } else {
75+ setAudioFinished ( true ) ;
76+ }
6677 } else {
67- setAudioFinished ( true ) ;
78+ if ( currentTime < seekableDuration && ! audioFinished ) {
79+ onProgress ( item . id , currentTime / seekableDuration ) ;
80+ } else {
81+ setAudioFinished ( true ) ;
82+ }
6883 }
6984 } ;
7085
@@ -129,10 +144,23 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
129144 // This is done for Expo CLI where we don't get file duration from file picker
130145 if ( item . duration === 0 ) {
131146 onLoad ( item . id , durationMillis / 1000 ) ;
147+ } else {
148+ // The duration given by the expo-av is not same as the one of the voice recording, so we take the actual duration for voice recording.
149+ if ( isVoiceRecording && item . duration ) {
150+ onLoad ( item . id , item . duration ) ;
151+ } else {
152+ onLoad ( item . id , durationMillis / 1000 ) ;
153+ }
132154 }
133155 // Update your UI for the loaded state
134156 if ( playbackStatus . isPlaying ) {
135- onProgress ( item . id , positionMillis / durationMillis ) ;
157+ if ( isVoiceRecording && item . duration ) {
158+ if ( positionMillis <= item . duration * 1000 ) {
159+ onProgress ( item . id , positionMillis / ( item . duration * 1000 ) ) ;
160+ }
161+ } else {
162+ onProgress ( item . id , positionMillis / durationMillis ) ;
163+ }
136164 } else {
137165 // Update your UI for the paused state
138166 }
@@ -355,6 +383,7 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
355383const styles = StyleSheet . create ( {
356384 audioInfo : {
357385 flexDirection : 'row' ,
386+ alignItems : 'center' ,
358387 } ,
359388 centerContainer : {
360389 flexGrow : 1 ,
0 commit comments