简体   繁体   English

HTML5视频源将无法在IE中成功更改

[英]HTML5 video source will not successfully change in IE

I'm going nuts over this problem. 我为这个问题疯了。 I have a script that changes the sources of a <video> tag, then reloads it and plays it. 我有一个脚本,可以更改<video>标签的来源,然后重新加载并播放它。 The problem is that I just can't get it to work on any version of Internet Explorer. 问题是我无法在任何版本的Internet Explorer上使用它。

I have an array of video sources called sequence.sources , containing: 我有一个称为sequence.sources的视频源数组,其中包含:

sequence.sources = ['video.webm', 'video.mp4', 'video.ogv'];

The sequences object is loaded from another array, so that's the dynamic aspect of it all. sequences对象是从另一个数组加载的,因此这就是所有动态方面。 The function I use to change the video sources is as follows: 我用来更改视频源的功能如下:

var videoElem = document.getElementById('video');

// Remove all sources
while (videoElem.firstChild) {
    videoElem.removeChild(video.firstChild);
}

// Add new sources
for (var i = 0; i < sequence.sources.length; i++) {
   var srcElem = document.createElement('source');
   srcElem.setAttribute('src', sequence.sources[i]);
   videoElem.appendChild(srcElem);
}

// Initiate video
videoElem.load();
videoElem.play();

This works perfectly on all browsers but IE. 这在IE以外的所有浏览器上均能完美运行。 What am I to do? 我是什么做的? I've already tried modifying the src attribute of the <video> tag directly, but that doesn't seem to work. 我已经尝试过直接修改<video>标记的src属性,但这似乎不起作用。 I've even tried removing the entire <video> tag and adding a new one with the updated sources. 我什至尝试删除整个<video>标签,并使用更新的源添加一个新标签。 No cigar. 没有雪茄。

This is possibily off topic, but I'm considering the possibility that I must add some .htaccess hack to make it work. 这可能不在主题范围内,但是我正在考虑是否必须添加一些.htaccess hack使其可行的可能性。 Any suggestions would be greatly appreciated. 任何建议将不胜感激。

My final thought is that all sources except the first one are somehow faulty and won't be played. 我的最终想法是,除第一个来源外,所有来源均存在某种错误,将无法播放。 Is there some way I can check their compatibility with IE? 有什么办法可以检查它们与IE的兼容性?

EDIT: Network tab on developer tools give me 206 partial as result of the http request. 编辑:开发人员工具上的“网络”选项卡给了我206 partial作为http请求的结果。 This is highly likely to be an encoding compatibility issue. 这很可能是编码兼容性问题。 I will probably close this question soon if that proves to be the case. 如果事实确实如此,我可能会尽快解决这个问题。

the problem is that you create source nodes and then try to change the src attribute. 问题是您创建了source节点,然后尝试更改src属性。 That does not work in IE. 在IE中不起作用。 Instead only use the src attribute. 而是仅使用src属性。 A complete solution can be found in my post here: https://stackoverflow.com/a/7905151/818732 ... try to google such things and add "stackoverflow" to get the best results. 完整的解决方案可以在我的文章中找到: https : //stackoverflow.com/a/7905151/818732 ...尝试在Google上搜索此类内容并添加“ stackoverflow”以获得最佳结果。

By the way: have you ever tried just adding the mp4 file directly as an attribute (in the html code)? 顺便说一句:您是否尝试过将mp4文件直接添加为属性(在html代码中)? if yes and it still does not work check if your server returns the correct mime-type for .mp4 files ( video/mp4 ). 如果是,并且仍然无法正常工作,请检查您的服务器是否为.mp4文件( video/mp4 )返回了正确的mime类型。

Last but not least - utilize caniuse.com to check for browser support. 最后但并非最不重要-利用caniuse.com检查浏览器支持。 For starters, here is the link for mp4s: http://caniuse.com/mpeg4 对于初学者,这是mp4的链接: http ://caniuse.com/mpeg4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM