Javascript 服务器对音频文件的请求在返回任何数据之前超时
运行代码检索音频文件时,我收到以下错误: 未能加载资源:网络::错误\u连接\u超时\u 我很确定这意味着加载超时的资源需要很长时间。但我不确定为什么会发生这种情况。我检查了一下,以确保它加载了正确的文件,并且是正确的 下面是html代码Javascript 服务器对音频文件的请求在返回任何数据之前超时,javascript,html,dom,html5-audio,Javascript,Html,Dom,Html5 Audio,运行代码检索音频文件时,我收到以下错误: 未能加载资源:网络::错误\u连接\u超时\u 我很确定这意味着加载超时的资源需要很长时间。但我不确定为什么会发生这种情况。我检查了一下,以确保它加载了正确的文件,并且是正确的 下面是html代码 <html> <head> <style> .titletext { color: white; display: block;
<html>
<head>
<style>
.titletext {
color: white;
display: block;
position: absolute;
font-size: 50px;
width: 1000px;
margin-left: 150px;
margin-right: 200px;
}
.nametext {
color: white;
display: block;
position: absolute;
font-size: 30px;
width: 600px;
margin-left: 500px;
margin-right: 200px;
margin-top: 600px;
}
.earthphoto {
display: block;
position: absolute;
margin-left: 400px;
margin-top: 150px;
}
</style>
</head>
<body onresize="changeWidth()" onload="changeWidth()">
<script type="text/javascript">
document.body.style.background = "black";
var changeWidth = function() {
screenwidth = window.innerWidth;
screenheight = window.innerHeight;
};
var changescene = function() {
var allvariables = Object.keys(window);
if (page === 1) {
allvariables.splice(9, 4);
}
page++;
};
var page = 1;
document.body.addEventListener("click", function() {
changescene()
});
var update = function() {
if (page === 1) {
document.body.innerHTML = "";
var text = document.createElement("p");
var textclass = document.createAttribute("class");
textclass.value = "titletext";
text.setAttributeNode(textclass);
text.appendChild(document.createTextNode("Welcome to Mikey's Google Earth Presentation!"));
document.body.appendChild(text);
var text2 = document.createElement("p");
text2class = document.createAttribute("class");
text2class.value = "nametext";
text2.setAttributeNode(text2class);
text2.appendChild(document.createTextNode("By Mikey Richards"));
document.body.appendChild(text2);
googleearthimage = document.createElement("img");
googleearthimage.setAttribute("src", "EARTH.png");
googleearthimage.setAttribute("class", "earthphoto");
document.body.appendChild(googleearthimage);
var music = document.createElement("audio");
var musiclink = document.createElement("source");
musiclink.src = "Test.mp3";
music.appendChild(musiclink);
document.body.appendChild(music);
} else if (page === 2) {
document.body.innerHTML = "";
}
}
setInterval(function() {
update();
}, 1000);
</script>
</body>
</html>
.titletext{
颜色:白色;
显示:块;
位置:绝对位置;
字体大小:50px;
宽度:1000px;
左边距:150像素;
右边距:200px;
}
.nametext{
颜色:白色;
显示:块;
位置:绝对位置;
字体大小:30px;
宽度:600px;
左边距:500px;
右边距:200px;
边缘顶部:600px;
}
.地球照片{
显示:块;
位置:绝对位置;
左边距:400px;
边缘顶部:150px;
}
document.body.style.background=“黑色”;
var changeWidth=函数(){
screenwidth=window.innerWidth;
屏幕高度=window.innerHeight;
};
var changeSecene=函数(){
var allvariables=Object.keys(窗口);
如果(第===1页){
所有变量。拼接(9,4);
}
page++;
};
var-page=1;
document.body.addEventListener(“单击”,函数(){
变更场景()
});
var update=函数(){
如果(第===1页){
document.body.innerHTML=“”;
var text=document.createElement(“p”);
var textclass=document.createAttribute(“类”);
textclass.value=“titletext”;
text.setAttributeNode(textclass);
appendChild(document.createTextNode(“欢迎来到Mikey的Google Earth演示文稿!”);
document.body.appendChild(文本);
var text2=document.createElement(“p”);
text2class=document.createAttribute(“类”);
text2class.value=“nametext”;
text2.setAttributeNode(text2class);
text2.appendChild(document.createTextNode(“由Mikey Richards编写”);
document.body.appendChild(text2);
googleearthimage=document.createElement(“img”);
setAttribute(“src”、“EARTH.png”);
setAttribute(“类”、“地球照片”);
document.body.appendChild(Google EarthImage);
var music=document.createElement(“音频”);
var musiclink=document.createElement(“源”);
musiclink.src=“Test.mp3”;
音乐.儿童(musiclink);
文件。身体。儿童(音乐);
}否则如果(第===2页){
document.body.innerHTML=“”;
}
}
setInterval(函数(){
更新();
}, 1000);
可以找到此代码的网站。确定。我发现他的问题是我没有调用音频上的播放功能。感谢您容忍我糟糕的编程技能。在您的链接页面上,它大约每秒成功加载一次
Test.mp3
。这可能(错误地?)通过中止排队传输来显示。