Вот код, который я сейчас использую: < /p>
Nghe nhạc Offline
body {
font-family: sans-serif;
background: #1a1a1a;
color: white;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
}
.player {
background: #333;
padding: 20px;
border-radius: 10px;
text-align: center;
}
button {
padding: 10px 20px;
font-size: 18px;
margin-top: 10px;
cursor: pointer;
}
#status {
margin-top: 15px;
font-size: 16px;
color: #00ffcc;
}
.error {
color: #ff4444 !important;
}
Tải và phát nhạc
document.getElementById("loadBtn").addEventListener("click", async () => {
const status = document.getElementById("status");
status.textContent = "
status.classList.remove("error");
try {
const response = await fetch(
"https://raw.githubusercontent.com/Huynh ... %20roi.txt"
);
const base64 = await response.text();
const binary = atob(base64.trim());
const bytes = new Uint8Array(binary.length);
for (let i = 0; i < binary.length; i++) {
bytes = binary.charCodeAt(i);
}
const blob = new Blob([bytes], { type: "audio/mp3" });
const url = URL.createObjectURL(blob);
const audio = document.getElementById("audioPlayer");
audio.src = url;
await audio.play();
status.textContent = "
} catch (err) {
status.textContent = "
status.classList.add("error");
console.error(err);
}
});
Подробнее здесь: https://stackoverflow.com/questions/796 ... ithub-file
Мобильная версия