今天是 2026-6-8 星期一 QQ:545684816 TEL:13979373522
首  页 | 汉字编码 | 科普知识 | 竞赛之窗 | 音乐美术 | 婺中电教  
HTML5中通过audio控制音频
发表时间:2024-2-2    浏览次数:2
在HTML5中通过js可以方便控制音频的播放、暂停、停止、静音等。
下面是HTML+javascript代码:
1、需要说明的是【停止】实际上将时间播放头置0,再执行暂停命令!并没有audio.sop()命令
2、并不能控制左右声道平衡
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7">
</head>
<body>
<audio id="audio" src="爱情根本靠不住.mp3"></audio>
<button id="musicPlay">播放/继续</button>
<button id="musicPause">暂停</button>
<button id="musicStop">停止</button>
<button id="musicMute">静音</button>
<button id="musicMax">最大音量</button>
</body>
</html>
<script tye="text/javascript">
var audio=document.getElementById("audio");
document.getElementById("musicPlay").onclick=function(){
       audio.play();
}
document.getElementById("musicPause").onclick=function(){
       audio.pause();
}
document.getElementById("musicStop").onclick=function(){
       audio.currentTime=0;
       audio.pause();
}
document.getElementById("musicMute").onclick=function(){
       audio.volume=0;
}
document.getElementById("musicMax").onclick=function(){
       audio.volume=1;
}
</script>

Copyright© 2006-2026, All rights reserved。
地址:紫阳镇天佑西路8号 站长:汪有万 建站时间:2006-9-1