gpt4 book ai didi

javascript - 未处理的 promise 拒绝 : NotSupportedError (DOM Exception 9): The operation is not supported

转载 作者:太空狗 更新时间:2023-10-29 16:38:49 28 4
gpt4 key购买 nike

这是我的第一个问题。

所以我有这个 github 页面,它可以与最新的 chromium 一起正常工作,但我无法让它在 safari 上工作。当我在 Safari 上单击播放按钮时,我得到了 Unhandled Promise Rejection: NotSupportedError (DOM Exception 9): The operation is not supported.

这是控制台错误的照片

enter image description here

https://kglearning.github.io/imon/angela.html

基本上,当页面加载时,它会发出一个 xhr 请求。加载音频资源文件,以便在按下播放按钮时用户不必等待声音。它在 chrome 上工作正常,理想情况下应该首先有某种加载屏幕,但我还没有走那么远,因为这个脚本在 Safari 11 上失败了。Angela 页面是我现在正在处理的唯一页面,直到这个问题是固定的。所以……这是怎么回事?我有点难过。

这是代码,但您应该从链接运行它。

<!doctype html>
<html lang="en">
<head>
<title>Imon</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap 4 Beta CSS -->
<link rel="stylesheet" href="./css/bootstrap.min.css">
</head>
<body>

<!-- Lazy formatting with Bootstrap 4 Beta.
Creating a container, jumbotron, and centering -->
<div class="container">
<div class="jumbotron">
<h1 class="text-center">Imon 爱蒙幼儿园</h1>
</div>

<!-- Lazy formatting with Bootstrap 4 Beta.
Students Section -->
<div class="row text-center">
<div class="col-sm">
<h2>Angela</h2>
<button type="button" id="play" class="btn btn-primary">Play</button>
</div>

</div>



</div>
</div>

<!-- JavaScript after the page loads -->

<script>
/*
This script has been purposly left un-minified, sourced, and
commented directly on this page. Why? a few reasons... I'm
not trying to hide my source. At the very least the comments
are here for educational purposes, but mainly all this was
done because I'm lazy and didn't want to tab between multiple
source files. So the JS was lazily left here. Deal with it.
*/

var getPageName = window.location.pathname.substring(window.location.pathname.lastIndexOf('/') + 1);
var studentName = getPageName.substr(0, getPageName.length - 5);


function createPlayButton(audioObject) {
var playButton = document.getElementById("play");
playButton.addEventListener("click", function() {
audioObject.play();
}, false );

}

function playAudio(audioObject2) {
audioObject2.play();
}
/*
This approach was chosen since service workers are still
a little too new for production environments, and I don't
like application cache which is all but removed from
modern browsers.
*/
var req = new XMLHttpRequest();
req.open('GET', './sounds/' + studentName + '.ogg', true);
req.responseType = 'blob';

req.onload = function() {
if (this.status === 200) {
var audio = new Audio(URL.createObjectURL(this.response));
audio.load();
createPlayButton(audio);
}
}
req.onerror = function() {

}

req.send();
</script>

<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="./js/jquery-3.2.1.slim.min.js"</script>
<script src="./js/popper.min.js"</script>
<script src="./js/bootstrap.min.js"</script>
</body>
</html>

编辑

我换了

var audio = new Audio(URL.createObjectURL(this.response));

//var audio = new Audio(URL.createObjectURL(this.response));
req.open('GET', './sounds/angela.ogg', true);

问题在 Safari 中仍然存在

为了更进一步,我现在将 req.open 更改为

req.open('GET', 'https://kglearning.github.io/imon/sounds/angela.ogg', true);

这仍然没有解决问题。请再次检查上面的 github 页面链接。

编辑:在尝试了很多不同的事情之后,我决定四处寻求脚本方面的帮助,最后被告知我忽略的最简单的事情......

SAFARI 不支持 OGG!

所以我将文件类型从 ogg 更改为 m4a,现在它可以在 Safari 中使用了。所有这些都适用于如此简单的事情。

最佳答案

事实证明 Safari 不支持 ogg。这就是错误发生的原因。

关于javascript - 未处理的 promise 拒绝 : NotSupportedError (DOM Exception 9): The operation is not supported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47962500/

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