【问题标题】:HTML5 video player with start time does not work on Internet Explorer带有开始时间的 HTML5 视频播放器在 Internet Explorer 上不起作用
【发布时间】:2014-12-28 18:31:21
【问题描述】:
我有下面的代码,视频从 483 秒开始。它适用于大多数浏览器,除了 IE10,它从 0:00 开始。
<video controls preload="metadata">
<source src="http://example.com/myvideo.mp4#t=483" type="video/mp4">
</video>
【问题讨论】:
标签:
html
internet-explorer
html5-video
internet-explorer-10
mp4
【解决方案1】:
根据这个问题
Setting HTML5 audio position
为了支持寻找和播放媒体的区域,
尚未下载,Gecko 使用 HTTP 1.1 字节范围请求
从搜索目标位置检索媒体。此外,如果您
不提供 X-Content-Duration 标头,Gecko 使用字节范围请求
寻找媒体的结尾(假设您提供 Content-Length
header) 以确定媒体的持续时间。
你可以使用 jQuery
$('video').bind('canplay', function() {
this.currentTime = 483;
});
【解决方案2】:
HTML5 视频元素让您开始在网页上使用视频元素。通过添加 JavaScript,您可以以编程方式创建自定义播放控件、获取和设置当前播放位置以及更改当前视频。您还可以应用执行时间。
您的 HTML 更改:
<video controls preload="metadata" id="Video1">
<source src="http://example.com/myvideo.mp4" type="video/mp4">
</video>
JS代码:
var video = document.getElementById("Video1");
if (video.canPlayType) { // tests that we have HTML5 video support
video.addEventListener("canplay", function(){
setTime(483); //specified time
}, false);
}
setTime函数:
function setTime(tValue) {
// if no video is loaded, this throws an exception
try {
if (tValue == 0) {
video.currentTime = tValue;
}
else {
video.currentTime += tValue;
}
} catch (err) {
// errMessage(err) // show exception
console.log("Video content might not be loaded");
}
}
您可以在Using JavaScript to control the HTML5 video player获取更多详细信息
【解决方案3】:
'#t' 语法是 W3C 的媒体片段 URI 规范的一部分,可以在 here. 找到 根据this 的文章,IE 不支持这一点,尽管其他主要浏览器支持。因此,在 IE 提供对此规范的支持之前,您必须使用 Javascript 控制播放。
有趣的是,我能够在 Microsoft 的 IE 反馈门户中找到 IE 用户对此问题的反馈。让我分享一下here.