【发布时间】:2016-10-07 01:15:45
【问题描述】:
我收到 DOMException: Failed to load because no supported source was found in video.play();线。我只有在添加 video.setAttribute('crossorigin', 'anonymous'); 后才遇到这个问题我正在开发移动应用程序,因此对于跨源,我需要添加此行。更新 chrome 50 版本后,我遇到了这个问题,然后它就可以正常工作了。
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
</head>
<body>
<script>
var video = document.createElement( 'video' );
video.id = 'video';
video.type = ' video/mp4; codecs="theora, vorbis" ';
video.src = "http://abcde.com/img/videos/what_is_design_thinking.mp4";
video.volume = .1;
video.setAttribute('crossorigin', 'anonymous');
video.load(); // must call after setting/changing source
$('body').html(video);
video.play();
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
$('body').append(canvas);
video.addEventListener('play', function() {
var $this = this; //cache
(function loop() {
if (!$this.paused && !$this.ended) {
ctx.drawImage($this, 0, 0);
setTimeout(loop, 1000 / 30); // drawing at 30fps
}
})();
}, 0);
</script>
</body>
</html>
【问题讨论】:
-
如果没有
crossorigin=anonymous,我会得到相同的结果。这让我们认为错误是正确的:它抱怨是因为 src url 不是视频(甚至无法解析 url)。 -
检查abcde.com/img/videos/what_is_design_thinking.mp4 是否真的存在。有时,只是文件不存在或返回格式不正确的文件!
标签: javascript html