-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMp3.html
More file actions
133 lines (125 loc) · 3.64 KB
/
Copy pathMp3.html
File metadata and controls
133 lines (125 loc) · 3.64 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
132
133
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style type="text/css" media="all">
body {
padding: 1em;
background: #1e1e1e;
box-sizing: border-box;
}
.grid {
display: grid;
grid-template-columns: 80% 20%;
}
#fileInput {
box-sizing: border-box;
padding: 5px;
width: 100%;
margin: 0;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
font-weight: 500;
color: #ffff;
border: 1px solid blue;
}
#audioPlayers {
width: 100%;
display: flex;
justify-content: center;
flex-wrap: wrap;
box-sizing: border-box;
}
#audioPlayers div {
display: flex;
justify-content: center;
flex-direction: column;
width: 100%;
align-items: center;
border-radius: 12px;
background: #6a1b9a;
user-select: none;
gap: 10px;
padding: 12px;
color: #ffff;
font-weight: 500;
margin-top: 12px;
transition: border 0.3s;
}
#audioPlayers div:hover {
border: 1px solid blue;
}
@media screen and (min-width: 400px) {
body {
padding: 3em;
}
#audioPlayers {
display: grid;
column-gap: 50px;
grid-template-columns: 1fr 1fr;
}
}
button {
border: 1px solid blue;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
}
button:hover {
background: #678ff1e4;
}
</style>
<title>Audio Player for Selected Files</title>
</head>
<body>
<div class="grid">
<input type="file" id="fileInput" multiple accept="audio/*" />
<button onclick="handleTheme()">Night</button>
</div>
<div id="audioPlayers"></div>
<script>
const audio = new Audio("./Sound/mixkit-plastic-bubble-click-1124.wav");
audio.addEventListener('canplaythrough', (event) => {
// Audio is ready to play
console.log('Audio is ready to play');
});
const button = document.querySelector("button");
const body = document.querySelector("body");
let day = false;
function handleTheme(e) {
day = !day;
body.style.background = day ? "#fff" : "#1e1e1e";
button.innerText = day ? "day" : "Night";
audio.play();
}
//_________________
let loading = false
let songs = [];
document
.getElementById("fileInput")
.addEventListener("change", handleFileSelect);
function handleFileSelect(event) {
loading = true
const audioPlayers = document.getElementById("audioPlayers");
audioPlayers.innerHTML = ""; // Clear previous audio elements
const files = event.target.files;
let length = files.length
for (let i = 0; i < length ; i++) {
console.log(files[i]);
if (files[i].type.startsWith("audio/")) {
const audioElement = document.createElement("audio");
audioElement.controls = true;
audioElement.src = URL.createObjectURL(files[i]);
console.log(URL.createObjectURL(files[i]));
songs.push(audioElement.src);
const listItem = document.createElement("div");
listItem.textContent = files[i].name;
listItem.appendChild(audioElement);
audioPlayers.appendChild(listItem);
console.log(songs);
}
}
}
</script>
</body>
</html>