Browse Source

improve video snapshot get

master
filesite 4 months ago
parent
commit
baaa54ba78
  1. 11
      www/js/beauty.js

11
www/js/beauty.js

@ -256,15 +256,15 @@ if ($('#pr-player').length > 0 && typeof(videojs) != 'undefined') {
var duration = myPlayer.duration(); var duration = myPlayer.duration();
//更新视频封面图和视频时长 //更新视频封面图和视频时长
if (duration && snapshotImg) { if (duration && snapshotImg && /^data:image\/.+;base64,/i.test(snapshotImg)) {
$('#poster_'+mc_video_id).attr('src', snapshotImg); $('#poster_'+mc_video_id).attr('src', snapshotImg);
$('#poster_'+mc_video_id).parent('a').find('.duration').text(formatDuration(duration)); $('#poster_'+mc_video_id).parent('a').find('.duration').text(formatDuration(duration));
}
saveVideoMeta(mc_video_id, { saveVideoMeta(mc_video_id, {
duration: duration, duration: duration,
snapshot: snapshotImg snapshot: snapshotImg
}); });
}
mc_video_id = ''; //reset mc_video_id = ''; //reset
} }
@ -343,11 +343,14 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') {
var ctx = canvas.getContext('2d'); var ctx = canvas.getContext('2d');
ctx.drawImage( video, 0, 0, canvas.width, canvas.height ); ctx.drawImage( video, 0, 0, canvas.width, canvas.height );
var snapshotImg = canvas.toDataURL('image/jpeg'); var snapshotImg = canvas.toDataURL('image/jpeg'),
duration = myPlayer.duration();
if (duration && snapshotImg && /^data:image\/.+;base64,/i.test(snapshotImg)) {
saveVideoMeta($('video.vjs-tech').attr('data-id'), { saveVideoMeta($('video.vjs-tech').attr('data-id'), {
duration: myPlayer.duration(), duration: duration,
snapshot: snapshotImg snapshot: snapshotImg
}); });
}
myPlayer.play(); myPlayer.play();
}); });

Loading…
Cancel
Save