[英]Suppress Load of media resource failed
I have in my html an audio tag, in which I have src="".我的 html 中有一个音频标签,其中有 src=""。 When I play music, I change the src value from javascript.
当我播放音乐时,我从 javascript 更改 src 值。 However, when loading a page, I get an error
但是,在加载页面时,出现错误
Invalid URI.无效的 URI。 Load of media resource failed.
媒体资源加载失败。 game.php All candidate resources failed to load.
game.php 所有候选资源加载失败。 Media load paused.
媒体加载暂停。
I know why, the source logically does not exist.我知道为什么,源逻辑上不存在。 Is there any way to tell the audio element not to try to load the src from the beginning?
有什么方法可以告诉音频元素不要从头开始加载 src 吗?
<div style="display: none;" >
<audio tabindex="0" id="audio" controls preload="auto" loop="true">
<source src="">
</audio>
</div>
Thanks谢谢
Simply create your <audio>
element without any <source>
s, like只需创建没有任何
<source>
的<audio>
元素,例如
<audio tabindex="0" id="audio" controls preload="auto" loop="true">
</audio>
Then add a <source>
during runtime, whenever needed/checked/validated, with something like eg:然后在运行时添加一个
<source>
,无论何时需要/检查/验证,例如:
var audio = document.getElementsByTagName('audio')[0];
var source = document.createElement('source');console.log(source);
source.setAttribute('src','http://somewhere');
audio.appendChild(source);
Remove <source>
from initial html and then...从初始 html 中删除
<source>
然后...
var a = new Audio('someaudio.mp3');
// File does not exist
a.onerror = function() {
//nothing
};
//File exists
a.onloadeddata = function() {
//add source from javascript
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.