我需要在 asp.net 页面上播放和暂停一个 .wav 文件,但我不能使用 flash,它需要是可能存在的最轻量级的解决方案。我找到了如何播放声音,但我找不到阻止它的方法。
这是我的代码:(使用元素“embed”它在 IE 中不起作用,但使用“bgsound”它在 Chrome 中不起作用)
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
var soundObject = null;
function PlaySound() {
if (soundObject != null) {
document.body.removeChild(soundObject);
soundObject = null;
}
soundObject = document.createElement("bgsound");
soundObject.setAttribute("src", "C:/sound1.wav");
soundObject.setAttribute("hidden", true);
soundObject.setAttribute("autostart", true);
document.body.appendChild(soundObject);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type = "button" onclick = "PlaySound()" value = "Play Sound" />
</form>
</body>
</html>