Repository navigation
Expand file tree
/
Copy pathspotify-embed.html
More file actions
131 lines (106 loc) · 3.81 KB
/
Copy pathspotify-embed.html
File metadata and controls
131 lines (106 loc) · 3.81 KB
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
<!DOCTYPE html>
<html>
<head>
<title>Spotify widget</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Audiowide&family=Bitcount+Grid+Single:wght@100..900&display=swap" rel="stylesheet">
<script src="https://open.spotify.com/embed/iframe-api/v1" async></script>
<script>
let player = null
let spotify = [
// Playlist
'spotify:playlist:37i9dQZEVXbMZ5PAcNTDXd',
// Episode
'spotify:episode:7makk4oTQel546B0PZlDM5',
'spotify:episode:43cbJh4ccRD7lzM2730YK3',
'spotify:episode:6I3ZzCxRhRkNqnQNo8AZPV',
// Playlist
'spotify:playlist:37i9dQZEVXbNG2KDcFcKOF',
]
window.onSpotifyIframeApiReady = (IFrameAPI) => {
const element = document.getElementById('spotify-iframe')
const options = {
uri: spotify[0],
// Podcast or playlist uri
// uri: 'spotify:playlist:37i9dQZEVXbMZ5PAcNTDXd',
}
// EmbedController
const callback = (EmbedController) => {
player = EmbedController
player.addListener("playback_started", handlePlaybackStart)
player.addListener('playback_update', handlePlaybackUpdate)
// player.loadUri(spotify[0])
// player.play()
// player.stop()
}
IFrameAPI.createController(element, options, callback)
}
function play() {
player.play()
}
function pause() {
player.pause()
}
// Change uri
function change(id) {
player.loadUri(spotify[id])
}
const handlePlaybackStart = (e) => {
const { playingURI } = e.data
console.log(`The playback has started for: ${playingURI}`)
}
const handlePlaybackUpdate = (e) => {
const { position, duration, isBuffering, isPaused, playingURI } = e.data
console.log(`Playback State updates:
position - ${position},
duration - ${duration},
isBuffering - ${isBuffering},
isPaused - ${isPaused},
playingURI - ${playingURI},
duration - ${duration}`
)
};
</script>
<style>
.iframe-script iframe {
min-height: 500px !important;
}
.iframe-embed iframe {
min-height: 700px !important;
}
body {
font-family: Audiowide;
}
button {
font-family: Audiowide;
float: left;
padding: 10px 20px;
border: none;
color: #fff;
background: #333;
margin: 15px;
margin-left: 0px;
cursor: pointer;
font-size: 18px;
border-radius: 10px;
}
</style>
</head>
<body>
<h2>Script</h2>
<button onclick="play()">Play</button>
<button onclick="pause()">Pause</button>
<button onclick="change(1)">Podcast 1</button>
<button onclick="change(2)">Podcast 2</button>
<button onclick="change(3)">Podcast 3</button>
<button onclick="change(4)">Playlist</button>
<div class="iframe-script">
<div id="spotify-iframe"></div>
</div>
<h2>Embed</h2>
<div class="iframe-embed">
<iframe data-testid="embed-iframe" src="https://open.spotify.com/embed/playlist/37i9dQZF1DX7zqr9q1MPG7?utm_source=generator&theme=0" width="100%" height="500" frameBorder="0" allowfullscreen="" allow="autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture" loading="lazy"></iframe>
</div>
</body>
</html>