简易音乐播放器html5代码
时间: 2023-05-30 18:04:14 浏览: 165
html5带背景的简洁音乐播放器代码
<!DOCTYPE html>
<html>
<head>
<title>简易音乐播放器</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css">
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
margin: 0;
padding: 0;
}
h1 {
font-size: 36px;
font-weight: bold;
text-align: center;
margin-top: 30px;
}
audio {
display: block;
margin: 20px auto;
}
.controls {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
margin: 20px auto;
width: 200px;
}
.controls button {
background-color: #4CAF50;
border: none;
color: white;
padding: 10px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
width: 100px;
}
.controls button:hover {
background-color: #3e8e41;
}
</style>
</head>
<body>
<h1>简易音乐播放器</h1>
<audio id="myAudio" controls>
<source src="music.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<div class="controls">
<button onclick="playAudio()">播放</button>
<button onclick="pauseAudio()">暂停</button>
<button onclick="stopAudio()">停止</button>
</div>
<script>
var audio = document.getElementById("myAudio");
function playAudio() {
audio.play();
}
function pauseAudio() {
audio.pause();
}
function stopAudio() {
audio.pause();
audio.currentTime = 0;
}
</script>
</body>
</html>
阅读全文