HTML 音乐播放器代码 - 简单易用
<!DOCTYPE html>
<html>
<head>
<title>Music Player</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
background-color: #eee;
font-family: Arial, sans-serif;
}
h1 {
text-align: center;
color: #333;
}
.container {
margin: 0 auto;
max-width: 600px;
padding: 20px;
}
.audio-player {
background-color: #fff;
border-radius: 5px;
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
padding: 20px;
text-align: center;
}
.audio-player audio {
display: block;
margin: 0 auto;
width: 100%;
max-width: 500px;
margin-bottom: 20px;
}
.audio-player button {
background-color: #333;
border: none;
border-radius: 5px;
color: #fff;
cursor: pointer;
font-size: 16px;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
margin-right: 10px;
}
.audio-player button:hover {
background-color: #555;
}
</style>
</head>
<body>
<div class="container">
<h1>Music Player</h1>
<div class="audio-player">
<audio controls>
<source src="music.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<button onclick="play()">Play</button>
<button onclick="pause()">Pause</button>
<button onclick="stop()">Stop</button>
</div>
</div>
<script>
var audio = document.querySelector('audio');
function play() {
audio.play();
}
function pause() {
audio.pause();
}
function stop() {
audio.pause();
audio.currentTime = 0;
}
</script>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/lQ6r 著作权归作者所有。请勿转载和采集!