gpt4 book ai didi

javascript - 浏览器中的Javascript音频支持-特质

转载 作者:行者123 更新时间:2023-12-03 01:37:10 25 4
gpt4 key购买 nike

我浏览了该网站和其他网站,找不到关于这种特质的任何解释,也找不到任何解决方案。

尽管在这些站点上有各种说法,但是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>

有任何想法吗?

最佳答案

Mozilla支持论坛的主持人cor-el为我解决了此问题。 Firefox不支持所有.wav选项。 Audacity将其保存为44100Hz。根据他的建议,我将其重新设置为48000Hz。

现在,它可以在Firefox中运行,并且可以继续在Edge,Chrome,Opera和Slimjet中运行。

当然,它在IE中仍然不起作用。 (叹)。显然,IE根本不支持.wav文件。它似乎也不支持.mp3或.ogg文件。

关于javascript - 浏览器中的Javascript音频支持-特质,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51627044/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com