【发布时间】:2014-07-15 00:18:01
【问题描述】:
我正在尝试在我的网站上嵌入 video.js 视频播放器。我正在运行带有 jquery-1.10.2 的 debian 7.5 / chrome / IceWeasel (thunderbird) 站进行测试。
期待的功能
从列表索引播放视频。
我列出了目录中包含的视频文件,将每个文件的超链接设置为:
<a class="IndexItem" href="#" id="404467" type="video/mime-type" data-video="video-file_name.mp4">My video #1</a>
....
点击事件由 javascript 代码管理。
点击视频索引时,会动态创建相应的源标签并加载视频播放器。
问题
视频已成功加载并播放,但是当我单击播放器停止按钮时,进度条仍会向前移动,直到到达流的末尾。
我该如何解决这个问题?
代码摘录
html
<video class="video-js vjs-default-skin" height="480" id="video-player" width="640" poster="/images/bubble-logo.png">
<source src="/path/to/my/video" type="video/mime-type"/>
<h3>Your browser does not support the video tag</h3>
</video>
video/mime_type 可以是 video/mp4、video/webm 或 video/ogg
javascript
$(document).ready(function() {
//---------------------
// Edit click event
//---------------------
$.each($(".IndexItem"), function(){
$(this).click(function(event){
event.preventDefault();
// href data-video attribute contains the video file name
// href type attribute contains the video mime-type
var filename = $(this).attr("data-video");
var mime = $(this).attr("type");
// removing previous sources
$('#video-player').empty();
playVideo(filename, mime);
});
});
});
function playVideo(filename, mime) {
// set set html source tag inside the video player div
loadSource(filename, mime);
videojs("video-player", {"controls":true}, function(){
// Player (this) is initialized and ready.
});
}
function loadSource(filename, mime){
var source = $('<source src="/videos/' + filename + '" type="' + mime + '"/>');
$('#video-player').append(source);
var warning = $('<h3>Your browser does not support the video tag</h3>');
$('#video-player').append(warning);
console.log("Creating new source :" + source);
}
也许我的方法不是正确的,因为我为每个请求创建了一个视频播放器实例(似乎不是很干净......)。假设不是,关于我的问题的问题仍然相关,因为它在我重新加载页面后第一次尝试打开视频时提出。
提前感谢您的帮助。
【问题讨论】:
标签: javascript jquery html video