Skip to content

Commit 5693df1

Browse files
committed
fix: async audio progress experience
1 parent d532cee commit 5693df1

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

package/src/components/Attachment/AudioAttachment.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
170170
}
171171

172172
if (playbackStatus.didJustFinish && !playbackStatus.isLooping) {
173+
onProgress(item.id, 1);
173174
// The player has just finished playing and will stop. Maybe you want to play something else?
174175
// status: opposite of pause,says i am playing
175176
handleEnd();
@@ -217,7 +218,7 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
217218
if (!Sound.Player) {
218219
initalPlayPause();
219220
}
220-
}, [item.paused]);
221+
}, [item.paused, isExpoCLI, pauseAudio, playAudio]);
221222

222223
const onSpeedChangeHandler = async () => {
223224
if (currentSpeed === 2.0) {
@@ -382,8 +383,8 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
382383

383384
const styles = StyleSheet.create({
384385
audioInfo: {
385-
flexDirection: 'row',
386386
alignItems: 'center',
387+
flexDirection: 'row',
387388
},
388389
centerContainer: {
389390
flexGrow: 1,

package/src/components/ProgressControl/WaveProgressBar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useCallback, useEffect, useMemo, useState } from 'react';
2-
import { Pressable, StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
2+
import { Platform, Pressable, StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
33
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
44
import Animated, { runOnJS, useAnimatedStyle, useSharedValue } from 'react-native-reanimated';
55

@@ -72,7 +72,7 @@ const ProgressControlThumb = ({ style }: { style?: StyleProp<ViewStyle> }) => {
7272
export const WaveProgressBar = React.memo(
7373
(props: WaveProgressBarProps) => {
7474
/* On Android, the seek doesn't work for AAC files, hence we disable progress drag for now */
75-
const showProgressDrag = true;
75+
const showProgressDrag = Platform.OS === 'ios';
7676
const {
7777
amplitudesCount = 70,
7878
filledColor,

package/src/hooks/useAudioPlayer.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,19 @@ export const useAudioPlayer = (props: UseSoundPlayerProps) => {
3131

3232
const seekAudio = async (currentTime: number) => {
3333
if (isExpoCLI) {
34-
if (soundRef.current?.setPositionAsync)
35-
await soundRef.current.setPositionAsync(currentTime * 1000);
34+
if (currentTime === 0) {
35+
// If currentTime is 0, we should replay the video from 0th position.
36+
if (soundRef.current?.replayAsync) {
37+
await soundRef.current.replayAsync({
38+
positionMillis: 0,
39+
shouldPlay: false,
40+
});
41+
}
42+
} else {
43+
if (soundRef.current?.setPositionAsync) {
44+
await soundRef.current.setPositionAsync(currentTime * 1000);
45+
}
46+
}
3647
} else {
3748
if (soundRef.current?.seek) soundRef.current.seek(currentTime);
3849
}

0 commit comments

Comments
 (0)