这是一个将 html5 视频的标记附加到 DOM 的脚本:
document.body.innerHTML = '<video id="video" controls="controls" src="http://mirror.cessen.com/blender.org/peach/trailer/trailer_iphone.m4v" type="video/mp4"></video>';
var el = document.getElementById('video');
document.body.removeChild(el);
document.body.appendChild(el);
jsfiddle 演示: http://jsfiddle.net/h8RLS/2/
这适用于所有经过测试的浏览器,iOS 上的 Safari 除外。在 iOS 中,当 HTMLVideoElement 重新附加到 DOM 时,它不再可播放。
有没有其他人解决或遇到过这个问题?
最佳答案
我没有 iPad,但可以在 iPhone 上重现您的问题。这似乎是一个 Webkit 错误,但可以通过更改视频的 src
属性轻松绕过它 - 我希望这足以满足您的场景。你可以在这里看到一个工作演示:
http://vidhtml5.appspot.com/jsembed.html
这是代码:
var el = document.getElementById('video');
el.src= "http://mirror.cessen.com/blender.org/peach/trailer/trailer_iphone.m4v";
el.load();
关于iphone - DOM 更改后,iPad 中的 HTML5 视频无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14514271/