1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
import React, { CSSProperties, useCallback } from "react";
import styled, { css } from "styled-components";
import { Lrc, LrcLine } from "react-lrc";
interface LineProps {
$active: boolean;
$next: boolean;
$animate: boolean;
$lrcColor: string;
$fontColor: string;
}
const Line = styled.div<LineProps>`
min-height: 10px;
padding: 14px 30px;
font-size: 40px;
font-family: "Roboto", sans-serif;
font-weight: 500;
text-align: center;
color: ${({ $fontColor }) => $fontColor};
background: ${({ $lrcColor }) => `linear-gradient(
to right,
rgba(0, 0, 0, 0) 50%,
${$lrcColor} 50%
)`};
background-size: 200% 100%;
background-position: right bottom;
${({ $animate }) =>
$animate &&
css`
transition:
color 0.3s ease,
background-position 0.5s ease;
`}
${({ $active }) =>
$active &&
css`
color: rgb(50, 50, 50);
font-weight: 700;
background-position: left bottom;
`}
`;
const lrcStyle: CSSProperties = {
flex: 1,
minHeight: 0,
overflow: "hidden !important",
};
interface LrcPlayerProps {
currentMillisecond: number;
lrc: string;
animate: boolean;
lrcColor: string;
fontColor: string;
}
const LrcPlayer: React.FC<LrcPlayerProps> = ({
currentMillisecond,
lrc,
animate,
lrcColor = "#C8BEBE",
fontColor = "rgb(72, 72, 72)",
}) => {
const lineRenderer = useCallback(
({ active, line: { content } }: { active: boolean; line: LrcLine }) => {
const next = active && content === "";
return (
<Line
$active={active}
$next={next}
$animate={animate}
$lrcColor={lrcColor}
$fontColor={fontColor}
>
{content}
</Line>
);
},
[animate, lrcColor, fontColor],
);
return (
<Lrc
lrc={lrc}
lineRenderer={lineRenderer}
currentMillisecond={currentMillisecond}
style={lrcStyle}
recoverAutoScrollInterval={0}
/>
);
};
export default LrcPlayer;
|