-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
154 lines (131 loc) · 4.16 KB
/
index.html
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/player.css">
<script src="js/app.js" defer></script>
<script src="js/rain.js" defer></script>
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/[email protected]/babel.min.js"></script>
</head>
<body>
<section class="layers">
<div class="layers__container">
<div class="layers__item layer-1" style="background-image: url(img/layer-1.jpg);"></div>
<div class="layers__item layer-2" style="background-image: url(img/layer-2.png);"></div>
<div class="layers__item layer-3">
<div id="container"></div>
</div>
<div class="layers__item layer-4">
<canvas class="rain"></canvas>
</div>
<div class="layers__item layer-5" style="background-image: url(img/layer-5.png);"></div>
<div class="layers__item layer-6" style="background-image: url(img/layer-6.png);"></div>
</div>
</section>
<script type="text/babel">
class AudioPlayer extends React.Component {
constructor(props) {
super(props);
this.audioRefs = [
React.createRef(),
React.createRef(),
React.createRef(),
];
this.state = {
isPlaying: [false, false, false],
volumes: [0.5, 0.5, 0.5],
tracks: [
{ src: 'sound/1.mp3' },
{ src: 'sound/2.mp3' },
{ src: 'sound/3.mp3' },
],
};
}
togglePlay = (index) => {
const audio = this.audioRefs[index].current;
const { isPlaying, tracks } = this.state;
const newIsPlaying = [...isPlaying];
newIsPlaying[index] = !newIsPlaying[index];
if (newIsPlaying[index]) {
audio.src = tracks[index].src;
audio.volume = this.state.volumes[index];
audio.play();
} else {
audio.pause();
}
this.setState({ isPlaying: newIsPlaying });
};
handleVolumeChange = (event, index) => {
const volume = event.target.value;
const audio = this.audioRefs[index].current;
audio.volume = volume;
const newVolumes = [...this.state.volumes];
newVolumes[index] = volume;
this.setState({ volumes: newVolumes });
};
handleEnded = (index) => {
const audio = this.audioRefs[index].current;
audio.currentTime = 0;
audio.play();
};
render() {
const { isPlaying, volumes, tracks } = this.state;
return (
<div className="audio-player">
<div className="buttons-container">
{tracks.map((track, index) => (
<div key={index} className="track-container">
<button
onClick={() => this.togglePlay(index)}
className={`play-button ${isPlaying[index] ? 'playing' : ''}`}
>
{isPlaying[index] ? 'Pause' : 'Play'}
</button>
<VolumeIndicator volume={volumes[index]} onChange={(e) => this.handleVolumeChange(e, index)} />
</div>
))}
</div>
{tracks.map((track, index) => (
<audio
key={index}
ref={this.audioRefs[index]}
src={track.src}
volume={volumes[index]}
onEnded={() => this.handleEnded(index)}
/>
))}
</div>
);
}
}
const VolumeIndicator = ({ volume, onChange }) => {
return (
<div className="volume-indicator">
<span className="volume-symbol">🔊</span>
<input
type="range"
min="0"
max="1"
step="0.01"
value={volume}
onChange={onChange}
className="volume-slider"
/>
</div>
);
};
ReactDOM.render(
<div>
<AudioPlayer/>
</div>,
document.querySelector("#container")
);
</script>
</body>
</html>