1bf6e62f2S猫头猫import React, {useState} from 'react'; 2bf6e62f2S猫头猫import {StyleSheet, Text, View} from 'react-native'; 3bf6e62f2S猫头猫import rpx from '@/utils/rpx'; 4bf6e62f2S猫头猫import Slider from '@react-native-community/slider'; 5242960d3S猫头猫import MusicQueue from '@/core/musicQueue'; 6bf6e62f2S猫头猫import timeformat from '@/utils/timeformat'; 7bf6e62f2S猫头猫import {fontSizeConst} from '@/constants/uiConst'; 8bf6e62f2S猫头猫 94060c00aS猫头猫export default function SeekBar() { 100b940038S猫头猫 const progress = MusicQueue.useProgress(400); 11bf6e62f2S猫头猫 const [tmpProgress, setTmpProgress] = useState<number | null>(null); 12bf6e62f2S猫头猫 13bf6e62f2S猫头猫 return ( 14bf6e62f2S猫头猫 <View style={style.wrapper}> 154060c00aS猫头猫 <Text style={style.text}> 164060c00aS猫头猫 {timeformat(tmpProgress ?? progress.position)} 174060c00aS猫头猫 </Text> 18bf6e62f2S猫头猫 <Slider 19bf6e62f2S猫头猫 style={style.slider} 20a92b50b7S猫头猫 minimumTrackTintColor={'#cccccc'} 21a92b50b7S猫头猫 maximumTrackTintColor={'#999999'} 22a92b50b7S猫头猫 thumbTintColor={'#dddddd'} 23bf6e62f2S猫头猫 minimumValue={0} 24bf6e62f2S猫头猫 maximumValue={progress.duration} 254060c00aS猫头猫 onValueChange={val => { 26bf6e62f2S猫头猫 setTmpProgress(val); 27bf6e62f2S猫头猫 }} 284060c00aS猫头猫 onSlidingComplete={val => { 29bf6e62f2S猫头猫 setTmpProgress(null); 30*ef714860S猫头猫 if (val >= progress.duration - 3) { 31*ef714860S猫头猫 val = progress.duration - 3; 32*ef714860S猫头猫 } 33bf6e62f2S猫头猫 MusicQueue.seekTo(val); 34bf6e62f2S猫头猫 }} 354060c00aS猫头猫 value={progress.position} 364060c00aS猫头猫 /> 37a92b50b7S猫头猫 <Text style={style.text}>{timeformat(progress.duration)}</Text> 38bf6e62f2S猫头猫 </View> 39bf6e62f2S猫头猫 ); 40bf6e62f2S猫头猫} 41bf6e62f2S猫头猫 42bf6e62f2S猫头猫const style = StyleSheet.create({ 43bf6e62f2S猫头猫 wrapper: { 44bf6e62f2S猫头猫 width: rpx(750), 45bf6e62f2S猫头猫 height: rpx(40), 46bf6e62f2S猫头猫 justifyContent: 'center', 47bf6e62f2S猫头猫 alignItems: 'center', 48bf6e62f2S猫头猫 flexDirection: 'row', 49bf6e62f2S猫头猫 }, 50bf6e62f2S猫头猫 slider: { 51bf6e62f2S猫头猫 width: rpx(550), 52bf6e62f2S猫头猫 height: rpx(40), 53bf6e62f2S猫头猫 }, 54bf6e62f2S猫头猫 text: { 55ec26b768S猫头猫 fontSize: fontSizeConst.description, 56bf6e62f2S猫头猫 includeFontPadding: false, 574060c00aS猫头猫 color: '#cccccc', 584060c00aS猫头猫 }, 59bf6e62f2S猫头猫}); 60