我有javascript代码来获取HTML5视频缩略图,我可以在点击按钮时获取视频缩略图,我希望使用currentTime属性获取此缩略图,我需要视频的缩略图一段时间,如视频的10秒,20秒和/或1秒
JavaScript的:
<script type="text/javascript">
(function() {
"use strict";
var video, $output;
var scale = 0.25;
var initialize = function() {
$output = $("#output");
video = $("#video").get(0);
$("#capture").click(captureImage);
};
var captureImage = function() {
var canvas = document.createElement("canvas");
canvas.width = video.videoWidth * scale;
canvas.height = video.videoHeight * scale;
canvas.getContext('2d')
.drawImage(video, 0, 0, canvas.width, canvas.height);
var img = document.createElement("img");
img.src = canvas.toDataURL();
$output.prepend(img);
};
$(initialize);
}());
</script>
HTML:
<video id="video" controls="controls">
<source src="uploads/post_videos/4d2fba78d9fcd7f59567e459c9b65404_131902_popcorntest.mp4" />
</video>
<button id="capture">Capture</button>
<div id="output"></div>