-
Notifications
You must be signed in to change notification settings - Fork 3
/
_basicPlayer.svelte
184 lines (179 loc) · 4.74 KB
/
_basicPlayer.svelte
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<script lang="ts">
import { onInterval, msToMinSec, SpotifyLogo } from './_utils';
import { fade } from 'svelte/transition';
// import icon from './spotify-icon-w.png';
import { cubicOut, cubicIn } from 'svelte/easing';
export let player: WebPlaybackPlayer, state: WebPlaybackState;
let hovered = false;
$: album_url = state.track_window.current_track.album.images?.find((i) => i.width === 64)?.url;
$: position = state.position;
/**
* When song is playing, adds progress to position.
* Use this to display progress of the song.
*/
onInterval(() => position += state.paused ? 0 : 300, 300);
</script>
<div class="basic-player" on:mouseenter={() => hovered = true} on:mouseleave={() => hovered = false}>
<div class="left-slot">
<div class="album-image">
{#key album_url}
<img src={album_url} alt="album cover"
in:fade="{{ easing: cubicIn, duration: 1000 }}"
out:fade="{{ easing: cubicOut, duration: 2000 }}"
/>
{/key}
</div>
<div class="play-pause" class:hidden={!hovered} on:click={() => player.togglePlay()}>
<div class="button" class:pause={!state.paused}></div>
</div>
</div>
<div class="right-slot">
<div class="track-info">
<div class="top">
<div class="prev" on:click={() => player.previousTrack()} class:hidden={!hovered}></div>
<div class="next" on:click={() => player.nextTrack()} class:hidden={!hovered}></div>
<div class="logo">
<img src={SpotifyLogo} alt="spotify logo" />
</div>
</div>
<div class="middle">
<div class="name"><b>{state.track_window.current_track.name}</b></div>
<div class="artists"><small>{state.track_window.current_track.artists.map((a) => a.name).join(', ')}</small></div>
</div>
<div class="bottom">
<div class="progress-bar">
<div class="progress" style={`width: ${position/state.duration*100}%;`}></div>
</div>
<div><small>{msToMinSec(state.duration)}</small></div>
</div>
</div>
</div>
</div>
<style>
.basic-player {
font-family: sans-serif, Helvetica, Arial;
font-size: smaller;
display: inline-grid;
position: relative;
grid-template-columns: 80px 1fr;
background: #3e3d3d;
color: #FFF;
box-shadow: 3px 2px 4px 0px #0003;
place-items: center;
border-radius: 3px;
}
.left-slot, .right-slot {
display: grid;
place-items: center;
border-radius: inherit;
height: 100%;
}
.right-slot {
box-shadow: inset 4px 0px 4px 0px #0003;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
min-width: 180px;
padding: 0 .5em;
}
.album-image, img {
border-top-left-radius: inherit;
border-bottom-left-radius: inherit;
height: 80px;
grid-column: 1/2;
grid-row: 1/2;
display: grid;
}
.track-info {
display: grid;
grid-template-rows: 22px 35px 23px;
width: 100%;
}
.play-pause {
background: #1db954;
height: 40px;
width: 40px;
box-sizing: border-box;
border-radius: 50%;
display: grid;
place-items: center;
grid-column: 1/2;
grid-row: 1/2;
z-index: 1;
cursor: pointer;
filter: drop-shadow(1px 1px 2px #0000003b);
}
.button {
box-sizing: border-box;
height: 20px;
padding-right: 2px;
border-color: transparent transparent transparent #FFF;
transition: 100ms all ease;
will-change: border-width;
border-style: solid;
border-width: 10px 0 10px 15px;
}
.next, .prev {
box-sizing: border-box;
height: 7.5px;
border-style: solid;
cursor: pointer;
}
.next {
border-color: transparent transparent transparent #1DB954;
border-width: 5px 0 5px 7.5px;
}
.prev {
border-color: transparent #1db954 transparent transparent;
border-width: 5px 7.5px 5px 0;
}
.button.pause {
border-style: double;
border-width: 0px 0 0px 15px;
}
.hidden {
display: none !important;
}
.top {
position: relative;
display: flex;
gap: .75em;
justify-content: flex-start;
place-items: center;
}
.middle {
display: flex;
align-content: flex-start;
justify-content: center;
flex-direction: column;
}
.bottom {
display: grid;
grid-template-columns: 1fr auto;
place-items: center;
gap: .25em;
color:#ffffff3b;
font-size: small;
}
.progress-bar {
background-color: #00000029;
border-radius: 3px;
height: 5px;
max-width: 100%;
width: 100%;
}
.progress {
background: #ffffff3b;
height: 5px;
border-radius: 3px;
border-top-left-radius: inherit;
border-bottom-left-radius: inherit;
}
.logo img {
position: absolute;
width: 15px;
height: 15px;
top: 4px;
right: -2px;
filter: brightness(0.5);
}
</style>