-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
156 lines (147 loc) · 5.12 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
155
156
<!DOCTYPE html>
<html lang="en">
<head>
<title>Zoe's Music</title>
<meta name="robots" content="noindex, nofollow">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.11"></script>
<link href="player.css" rel="stylesheet">
<link href="#" rel="shortcut icon" />
</head>
<body>
<div id="app">
<div class="player">
<div class="card" v-for="(song,index) in songs" :key="song.id">
<div class="container">
<img class="photo" :src="song.image" :alt="song.title" />
<div class="button">
<img class src="./images/play-pause.png" alt="play/pause" v-bind:class="[song.spin ? 'spin' : '']" @click="toggleSpin(song)" @click.prevent="isPlaying? pause(song) : play(song)" /><span v-text="song.title"></span>
<audio :src="song.src">
</div>
<div id="bar">
<div id="buffer-bar" :key="song.id" :style="{ width: song.buffer }">
<div id="progress-bar" :key="song.id" :style="{ width: song.progress }"></div>
</div>
</div>
</div>
</div>
</div>
<footer><p>© Zoe Chang. All rights reserved (Library of Congress).</p>
<p>All songs written, composed, arranged, performed, recorded, and produced by Zoe Chang.</p>
<p>Special thanks: guitars, bass, and drums by Agostia @Alone.</p></footer>
</div>
</body>
<script>
const App = new Vue({
el: '#app',
data: () => ({
isPlaying: false,
activeSong: 0,
songs: [{
id: '0',
title: 'Fly',
file: new Audio('songs/fly.mp3'),
src: 'songs/fly.mp3',
image: 'images/bird.jpg',
isPlaying: false,
spin: false,
progress: "0%",
buffer: "0%"
},
{
id: '1',
title: 'Closer',
file: new Audio('songs/closer.mp3'),
src: 'songs/closer.mp3',
image: 'images/world.jpg',
isPlaying: false,
spin: false,
progress: "0%",
buffer: "0%"
},
{
id: '2',
title: 'It Will Never End',
file: new Audio('songs/it-will-never-end.mp3'),
src: 'songs/it-will-never-end.mp3',
image: 'images/forever.jpg',
isPlaying: false,
spin: false,
progress: "0%",
buffer: "0%"
},
{
id: '3',
title: 'Alone',
file: new Audio('songs/alone.mp3'),
src: 'songs/alone.mp3',
image: 'images/rain.jpg',
isPlaying: false,
spin: false,
progress: "0%",
buffer: "0%"
},
{
id: '4',
title: 'There Will Always Be An Open Door',
file: new Audio('songs/open-door.mp3'),
src: 'songs/open-door.mp3',
image: 'images/door.jpg',
isPlaying: false,
spin: false,
progress: "0%",
buffer: "0%"
},
{
id: '5',
title: 'Hello, Hello, Hello',
file: new Audio('songs/hello.mp3'),
src: 'songs/hello.mp3',
image: 'images/hello.jpg',
isPlaying: false,
spin: false,
progress: "0%",
buffer: "0%"
}
]
}),
mounted() {
this.load();
},
methods: {
load(song, index) {
if (index !== undefined) {
this.activeSong = index;
}
this.audio = this.songs[this.activeSong].file;
this.audio.addEventListener('pause', () => { this.isPlaying = false; });
this.audio.addEventListener('play', () => { this.isPlaying = true; });
},
play(song) {
song.file.play();
this.isPlaying = true;
song.spin = true;
song.file.addEventListener("timeupdate", () => {
song.progress = (song.file.currentTime / parseInt(song.file.duration) * 100 || 0) + "%";
let buffered = song.file.buffered;
song.buffer = Math.round(100 * buffered.end(0) / song.file.duration) + "%";
});
},
pause(song) {
song.file.pause();
this.isPlaying = false;
song.spin = false;
},
toggleSpin(song) {
if (this.isPlaying) {
song.spin = true;
} else {
song.spin = false;
}
song.file.addEventListener("ended", () => { this.isPlaying = false; song.spin = false; });
}
}
});
</script>
</html>