added the audio rate

This commit is contained in:
Reinaldo Neto 2023-08-10 15:55:40 -03:00
parent 7e65c9fd71
commit bf77b6ccc3
4 changed files with 53 additions and 1 deletions

View File

@ -0,0 +1,25 @@
import React, { useState } from 'react';
import { Text } from 'react-native';
import styles from './styles';
import { useTheme } from '../../../../theme';
import Touchable from '../../Touchable';
const AudioRate = ({ onChange }: { onChange: (value: number) => void }) => {
const [rate, setRate] = useState(1.0);
const { colors } = useTheme();
const onPress = () => {
const nextRate = rate === 2.0 ? 0.5 : rate + 0.5;
setRate(nextRate);
onChange(nextRate);
};
return (
<Touchable onPress={onPress} style={[styles.containerAudioRate, { backgroundColor: colors.audioRateBackground }]}>
<Text style={[styles.audioRateText, { color: colors.audioRateText }]}>{rate}x</Text>
</Touchable>
);
};
export default AudioRate;

View File

@ -19,6 +19,7 @@ import { fetchAutoDownloadEnabled } from '../../../../lib/methods/autoDownloadPr
import styles from './styles';
import Slider from './Slider';
import Loading from './Loading';
import AudioRate from './AudioRate';
interface IButton {
loading: boolean;
@ -129,6 +130,10 @@ const MessageAudio = ({ file, getCustomEmoji, author, isReply, style }: IMessage
}
};
const setRate = async (value = 1.0) => {
await sound.current?.setRateAsync(value, true);
};
const handleDownload = async () => {
setLoading(true);
try {
@ -249,7 +254,7 @@ const MessageAudio = ({ file, getCustomEmoji, author, isReply, style }: IMessage
>
<Button disabled={isReply} loading={loading} paused={paused} cached={cached} onPress={onPress} />
<Slider sound={sound.current} thumbColor={thumbColor} onEndCallback={onEnd} />
<View style={{ width: 36, height: 24, backgroundColor: '#999', borderRadius: 4, marginRight: 16 }} />
<AudioRate onChange={setRate} />
</View>
</>
);

View File

@ -50,6 +50,19 @@ const styles = StyleSheet.create({
width: 12,
borderRadius: 6,
zIndex: 3
},
containerAudioRate: {
width: 36,
height: 24,
borderRadius: 4,
marginRight: 16,
justifyContent: 'center',
alignItems: 'center',
overflow: 'hidden'
},
audioRateText: {
fontSize: 14,
...sharedStyles.textBold
}
});

View File

@ -102,6 +102,9 @@ export const colors = {
overlayColor: '#1F2329B2',
audioPlayerPrimary: '#156FF5',
audioPlayerSecondary: '#CBCED1',
audioRateBackground: '#E4E7EA',
audioRateText: '#1F2329',
audioTimeText: '#2F343D',
...mentions,
...callButtons
},
@ -181,6 +184,9 @@ export const colors = {
overlayColor: '#1F2329B2',
audioPlayerPrimary: '#3976D1',
audioPlayerSecondary: '#404754',
audioRateBackground: '#353B45',
audioRateText: '#E4E7EA',
audioTimeText: '#E4E7EA',
...mentions,
...callButtons
},
@ -260,6 +266,9 @@ export const colors = {
overlayColor: '#1F2329B2',
audioPlayerPrimary: '#3976D1',
audioPlayerSecondary: '#404754',
audioRateBackground: '#353B45',
audioRateText: '#E4E7EA',
audioTimeText: '#E4E7EA',
...mentions,
...callButtons
}