-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
86 lines (82 loc) · 2.93 KB
/
index.html
File metadata and controls
86 lines (82 loc) · 2.93 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BlueSPAM</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
background: linear-gradient(to bottom right, #121212, #1c1c1c);
color: #ffffff;
}
.container {
margin-top: 50px;
}
.btn-custom {
background-color: #6200ea;
color: #ffffff;
}
.btn-custom:hover {
background-color: #3700b3;
}
.device-list-item {
background: #292929;
margin: 5px 0;
padding: 10px;
border-radius: 5px;
text-align: center;
}
.audio-controls {
margin-top: 20px;
}
.audio-upload {
display: none;
}
</style>
</head>
<body>
<div class="container text-center">
<h1>Bluetooth Audio Devices in Your Radius</h1>
<button id="scan-button" class="btn btn-custom mt-3">Scan for Devices</button>
<ul id="device-list" class="list-unstyled mt-3"></ul>
<div class="audio-controls mt-5">
<input type="file" id="audio-upload" class="audio-upload" accept="audio/*">
<button id="upload-button" class="btn btn-custom">Load Audio</button>
<br>
<audio id="audio-player" controls class="mt-3">
Your browser does not support the audio element.
</audio>
</div>
</div>
<script>
document.querySelector('#scan-button').addEventListener('click', async () => {
try {
const options = {
acceptAllDevices: true,
optionalServices: ['generic_access']
};
const device = await navigator.bluetooth.requestDevice(options);
const listItem = document.createElement('li');
listItem.textContent = device.name || `Unknown Device (${device.id})`;
listItem.className = 'device-list-item';
document.querySelector('#device-list').appendChild(listItem);
} catch (error) {
console.log('Error: ' + error);
}
});
document.querySelector('#upload-button').addEventListener('click', () => {
document.querySelector('#audio-upload').click();
});
document.querySelector('#audio-upload').addEventListener('change', (event) => {
const audioFile = event.target.files[0];
if (audioFile) {
const audioPlayer = document.querySelector('#audio-player');
audioPlayer.src = URL.createObjectURL(audioFile);
audioPlayer.load();
audioPlayer.play();
}
});
</script>
</body>
</html>