import React, {useRef, useState} from 'react';
import {StyleSheet, Text, View} from 'react-native';
import rpx from '@/utils/rpx';
import Slider from '@react-native-community/slider';
import timeformat from '@/utils/timeformat';
import {fontSizeConst} from '@/constants/uiConst';
import TrackPlayer from '@/core/trackPlayer';
interface ITimeLabelProps {
time: number;
}
function TimeLabel(props: ITimeLabelProps) {
return {timeformat(props.time)};
}
export default function SeekBar() {
const progress = TrackPlayer.useProgress(1000);
const [tmpProgress, setTmpProgress] = useState(null);
const slidingRef = useRef(false);
return (
{
slidingRef.current = true;
}}
onValueChange={val => {
if (slidingRef.current) {
setTmpProgress(val);
}
}}
onSlidingComplete={val => {
slidingRef.current = false;
setTmpProgress(null);
if (val >= progress.duration - 2) {
val = progress.duration - 2;
}
TrackPlayer.seekTo(val);
}}
value={progress.position}
/>
);
}
const style = StyleSheet.create({
wrapper: {
width: '100%',
height: rpx(40),
justifyContent: 'center',
alignItems: 'center',
flexDirection: 'row',
},
slider: {
width: '73%',
height: rpx(40),
},
text: {
fontSize: fontSizeConst.description,
includeFontPadding: false,
color: '#cccccc',
},
});