-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex_spotify.html
More file actions
81 lines (70 loc) · 2.26 KB
/
Copy pathindex_spotify.html
File metadata and controls
81 lines (70 loc) · 2.26 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
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>Spotify QR Scanner</title>
<script src="https://unpkg.com/html5-qrcode"></script>
<style>
body {
font-family: sans-serif;
text-align: center;
padding: 2rem;
}
iframe {
margin-top: 2rem;
border-radius: 12px;
width: 100%;
max-width: 600px;
height: 80px;
border: none;
}
#reader {
width: 300px;
margin: 0 auto;
}
</style>
</head>
<body>
<h1>Spotify QR-Code Scanner</h1>
<div id="reader"></div>
<div id="result"></div>
<iframe id="spotifyPlayer" allow="autoplay; encrypted-media;" loading="lazy"></iframe>
<script>
function parseSpotifyLink(link) {
// Prüft auf spotify:track:ID oder https://open.spotify.com/track/ID
const uriMatch = link.match(/^spotify:track:([a-zA-Z0-9]+)$/);
const urlMatch = link.match(/^https:\/\/open\.spotify\.com\/track\/([a-zA-Z0-9]+)/);
if (uriMatch) {
return uriMatch[1]; // trackId aus URI
} else if (urlMatch) {
return urlMatch[1]; // trackId aus URL
}
return null;
}
const scanner = new Html5Qrcode("reader");
scanner.start(
{ facingMode: "environment" },
{
fps: 10,
qrbox: 250
},
qrCodeMessage => {
const trackId = parseSpotifyLink(qrCodeMessage);
if (trackId) {
const embedUrl = `https://open.spotify.com/embed/track/${trackId}`;
document.getElementById("spotifyPlayer").src = embedUrl;
document.getElementById("result").innerText = "Song geladen!";
} else {
document.getElementById("result").innerText = "Ungültiger Spotify-Link!";
}
scanner.stop(); // Stoppt nach erstem Scan
},
errorMessage => {
// still ignorieren
}
).catch(err => {
console.error("Scanner-Fehler:", err);
});
</script>
</body>
</html>