Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,17 @@ const RenderListItem = React.memo(
const handleButtonAction = () => {
if (playerState === PlayerState.stopped) {
setCurrentPlaying(item.path);
} else if (playerState === PlayerState.playing) {
ref.current?.pausePlayer();
} else {
setCurrentPlaying('');
ref.current?.resumePlayer();
}
};

const handleStopAction = () => {
setCurrentPlaying('');
};

useEffect(() => {
if (currentPlaying !== item.path) {
ref.current?.stopPlayer();
Expand All @@ -90,19 +96,38 @@ const RenderListItem = React.memo(
onPress={handleButtonAction}
style={styles.playBackControlPressable}>
{isLoading ? (
<ActivityIndicator color={'#FF0000'} />
<ActivityIndicator color={'#FFFFFF'} />
) : (
<FastImage
source={
playerState === PlayerState.stopped
playerState !== PlayerState.playing
? Icons.play
: Icons.stop
: Icons.pause
}
style={styles.buttonImage}
resizeMode="contain"
/>
)}
</Pressable>
<Pressable
disabled={PlayerState.stopped == playerState}
onPress={handleStopAction}
style={styles.playBackControlPressable}>
{isLoading ? (
<ActivityIndicator color={'#FFFFFF'} />
) : (
<FastImage
source={Icons.stop}
style={[
styles.stopButton,
{
opacity: playerState === PlayerState.stopped ? 0.5 : 1,
},
]}
resizeMode="contain"
/>
)}
</Pressable>
<Waveform
containerStyle={styles.staticWaveformView}
mode="static"
Expand Down
1 change: 1 addition & 0 deletions example/src/assets/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export const Icons = {
mic: require('./mic.png'),
logo: require('./logo.png'),
delete: require('./delete.png'),
pause: require('./pause.png'),
};
Binary file added example/src/assets/icons/pause.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions example/src/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ const styles = (params: StyleSheetParams = {}) =>
tintColor: Colors.white,
alignSelf: 'flex-end',
},
stopButton: {
height: scale(22),
width: scale(22),
alignSelf: 'center',
},
pinkButtonImage: {
height: scale(22),
width: scale(22),
Expand Down
11 changes: 10 additions & 1 deletion src/components/Waveform/Waveform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const Waveform = forwardRef<IWaveformRef, IWaveform>((props, ref) => {
const viewRef = useRef<View>(null);
const scrollRef = useRef<ScrollView>(null);
const isLayoutCalculated = useRef<boolean>(false);
const isAutoPaused = useRef<boolean>(false);
const [waveform, setWaveform] = useState<number[]>([]);
const [viewLayout, setViewLayout] = useState<LayoutRectangle | null>(null);
const [seekPosition, setSeekPosition] = useState<NativeTouchEvent | null>(
Expand Down Expand Up @@ -518,11 +519,14 @@ export const Waveform = forwardRef<IWaveformRef, IWaveform>((props, ref) => {
if (panMoving) {
if (playerState === PlayerState.playing) {
pausePlayerAction();
isAutoPaused.current = true;
}
} else {
if (playerState === PlayerState.paused) {
if (playerState === PlayerState.paused && isAutoPaused.current) {
startPlayerAction();
}

isAutoPaused.current = false;
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [panMoving]);
Expand Down Expand Up @@ -559,6 +563,11 @@ export const Waveform = forwardRef<IWaveformRef, IWaveform>((props, ref) => {
(onPanStateChange as Function)(false);
setPanMoving(false);
},
onPanResponderRelease: e => {
setSeekPosition(e.nativeEvent);
(onPanStateChange as Function)(false);
setPanMoving(false);
},
})
).current;

Expand Down