From baaa54ba784f48f00d2cd9493acc866e57c58fee Mon Sep 17 00:00:00 2001 From: filesite Date: Tue, 16 Jul 2024 12:39:35 +0800 Subject: [PATCH] improve video snapshot get --- www/js/beauty.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/www/js/beauty.js b/www/js/beauty.js index f6af14b..2cc8fcb 100644 --- a/www/js/beauty.js +++ b/www/js/beauty.js @@ -256,15 +256,15 @@ if ($('#pr-player').length > 0 && typeof(videojs) != 'undefined') { 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).parent('a').find('.duration').text(formatDuration(duration)); - } - saveVideoMeta(mc_video_id, { - duration: duration, - snapshot: snapshotImg - }); + saveVideoMeta(mc_video_id, { + duration: duration, + snapshot: snapshotImg + }); + } mc_video_id = ''; //reset } @@ -343,11 +343,14 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') { var ctx = canvas.getContext('2d'); ctx.drawImage( video, 0, 0, canvas.width, canvas.height ); - var snapshotImg = canvas.toDataURL('image/jpeg'); - saveVideoMeta($('video.vjs-tech').attr('data-id'), { - duration: myPlayer.duration(), - snapshot: snapshotImg - }); + 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'), { + duration: duration, + snapshot: snapshotImg + }); + } myPlayer.play(); });