-
Notifications
You must be signed in to change notification settings - Fork 17
/
AudioPlayer.js
79 lines (72 loc) · 2.25 KB
/
AudioPlayer.js
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
import useAudio from "../hooks/useAudio";
import {Slider} from "antd";
import { useIPFS } from "../hooks/useIPFS";
import "./AudioPlayer.css";
import { SoundOutlined, StepBackwardOutlined, StepForwardOutlined, PlayCircleFilled, PauseCircleFilled} from "@ant-design/icons";
const Player = ({ url }) => {
const {resolveLink} = useIPFS();
const [
playing,
duration,
toggle,
toNextTrack,
toPrevTrack,
trackProgress,
onSearch,
onSearchEnd,
onVolume,
trackIndex
] = useAudio(url);
const minSec = (secs) => {
const minutes = Math.floor(secs / 60);
const returnMin = minutes < 10 ? `0${minutes}` : minutes;
const seconds = Math.floor(secs % 60);
const returnSec = seconds < 10 ? `0${seconds}` : seconds;
return `${returnMin}:${returnSec}`;
};
return (
<>
<div className="buttons" style={{width:"300px", justifyContent:"start"}}>
<img className="cover" src={resolveLink(JSON.parse(url[trackIndex].metadata).image)} alt="currentCover" />
<div>
<div className="songTitle">{JSON.parse(url[trackIndex].metadata).name}</div>
<div className="songAlbum">{url[trackIndex].name}</div>
</div>
</div>
<div>
<div className="buttons">
<StepBackwardOutlined className="forback" onClick={toPrevTrack} />
{playing ?
<PauseCircleFilled className="pauseplay" onClick={toggle} /> :
<PlayCircleFilled className="pauseplay" onClick={toggle} />
}
<StepForwardOutlined className="forback" onClick={toNextTrack} />
</div>
<div className="buttons">
{minSec(trackProgress)}
<Slider
value={trackProgress}
step={1}
min={0}
max={duration ? duration : 0}
className="progress"
tooltipVisible={false}
onChange={(value) => onSearch(value)}
onAfterChange={onSearchEnd}
/>
{duration ? minSec(Math.round(duration)) : "00:00"}
</div>
</div>
<div className="soundDiv">
<SoundOutlined />
<Slider
className="volume"
defaultValue={100}
tooltipVisible={false}
onChange={(value) => onVolume(value/100)}
/>
</div>
</>
);
};
export default Player;