我浏览了这个网站和其他网站,找不到任何解释,也找不到任何解决方案来解决这个问题。
尽管这些不同的站点上说了什么,但Javascript和HTML5 DOM音频似乎并不能在所有的浏览器上工作,正如在各个站点上的各种讨论中所指出的那样。
<html>
<head>
</head>
<body>
<audio id="buttonAudio" src="buttonClick.wav"></audio>
<button onclick="newGame00()">New Game 00</button>
<button onclick="newGame01()">New Game 01</button>
<button onclick="newGame02()">New Game 02</button>
<button onclick="newGame03()">New Game 03</button>
<button onclick="newGame04()">New Game 04</button>
<button onclick="newGame05()">New Game 05</button>
<button onclick="newGame06()">New Game 06</button>
<script>
// W3 Schools (https://www.w3schools.com/html/html5_audio.asp) says Firefox has
// supported HTML5 audio since version 3.5, and Internet Explorer has supported
// it since version 9.0.
// W3 Schools also (https://www.w3schools.com/jsref/met_audio_play.asp) says
// Firefox supports the HTML5 DOM Audio object, and Internet Explorer has done
// so since version 9.0. In fact, this W3 Schools page specifically recommends
// the method I've implemented via the "New Game 06" button.
// Nevertheless:
// I've tried all six of these methods for getting a button click in javascript.
// None of them work in version 61.0.1 (64-bit) of Mozilla Firefox.
// None of them work in version 11.0.9600.19080 of Internet Explorer.
// All six of them work in version 41.16299.371.0 of Edge.
// All six of them work in version 67.0.3396.99 (64-bit) of Google Chrome.
// All six of them work in version 54.0.2952.64 of Opera.
// All six of them work in version 19.0.2.0 (32-bit) of Slimjet.
var buttonClick = new Audio("buttonClick.wav");
var x = document.getElementById('buttonAudio');
function newGame00() {
buttonClick.play();
}
function newGame01() {
buttonAudio.play();
}
function newGame02() {
doit02();
}
function newGame03() {
doit03();
}
function newGame04() {
document.getElementById('buttonAudio').play();
}
function newGame05() {
doit05();
}
function newGame06() {
x.play();
}
async function doit02() {
buttonClick.play();
}
async function doit03() {
buttonAudio.play();
}
async function doit05() {
document.getElementById('buttonAudio').play();
}
</script>
</body>
有什么想法吗?
发布于 2018-08-06 03:19:18
cor-el,Mozilla支持论坛的主持人,为我解决了这个问题。火狐并不支持所有的.wav选项。Audacity用44100 at保存了它。根据他的建议,我用48000赫兹重做了一遍。
现在它可以在Firefox上运行,也可以继续在Edge,Chrome,Opera和Slimjet上运行。
当然,它仍然不能在IE中工作。(叹息)。显然,IE根本不支持.wav文件。它似乎也不支持.mp3或.ogg文件。
https://stackoverflow.com/questions/51627044
复制相似问题