假设网页上有一个媒体(视频)播放器。
在闪存上,
<button name="test" onclick="alert(Math.floor(jwplayer().getPosition())+ 'secs elapsed!');">elapsed time</button>
此代码显示视频的经过时间
在 HTML5 上,
<button name="test" onclick="alert(Math.floor(document.getElementById('video').currentTime) + 'secs elapsed!');">elapsed time</button>
此代码还显示视频的经过时间
我正在考虑存储所有评论,并且它已经过时间进入数据库。
然后它会在用户加载页面时自动加载特定视频的所有评论。
然后它会随着时间的流逝显示每条评论(我的图像是弹出的)
jQuery(或javascript)有可能吗?如果有怎么办?谁能告诉我如何轻松实现。
如果有这样的评论
- 在 5 秒时“你好!5 秒过去了”
- 在 20 秒时“你好!20 秒过去了”
- 在 35 秒时“你好!35 秒过去了”
- 在 35 秒时“你好!35 秒已经过去。第 2 部分”
- 在 60 秒时“你好!35 秒过去了”
更新:
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>Test</title>
<script src="http://code.jquery.com/jquery-1.10.2.js" type="text/javascript"></script>
<meta name="keywords" content="">
<meta name="description" content="">
<script type="text/javascript">
jQuery(document).ready(function () {
var comments = [{'time':'5','message':'hello! 5 secs has past'},{'time':'10','message':'hello! 10 secs has past'},{'time':'30','message':'hello! 15 secs has past'}];
$('#video').on('timeupdate',function(e){
showComments(this.currentTime);
});
function showComments(time){
var comments = findComments(time);
$.each(comments,function(i,comment){
alert(comment.message);
});
}
function findComments(time){
return $.grep(comments, function(item){
return item.time == time.toFixed();
});
}
}
</script>
</head>
<body>
<video id='video'
controls preload='none'
poster="http://media.w3.org/2010/05/sintel/poster.png">
<source id='mp4'
src="http://media.w3.org/2010/05/sintel/trailer.mp4"
type='video/mp4'>
<source id='webm'
src="http://media.w3.org/2010/05/sintel/trailer.webm"
type='video/webm'>
<source id='ogv'
src="http://media.w3.org/2010/05/sintel/trailer.ogv"
type='video/ogg'>
<p>Your user agent does not support the HTML5 Video element.</p>
</video>
</body></html>