diff --git a/themes/beauty/views/layout/main.php b/themes/beauty/views/layout/main.php index 289e7aa..3103bde 100644 --- a/themes/beauty/views/layout/main.php +++ b/themes/beauty/views/layout/main.php @@ -14,6 +14,7 @@ require_once __DIR__ . '/../../../../plugins/Html.php'; + @@ -98,6 +99,7 @@ require_once __DIR__ . '/../../../../plugins/Html.php'; + diff --git a/themes/beauty/views/site/index.php b/themes/beauty/views/site/index.php index f820a1e..1317d7f 100644 --- a/themes/beauty/views/site/index.php +++ b/themes/beauty/views/site/index.php @@ -259,7 +259,10 @@ eof; echo << - {$file['filename']} + {$file['filename']}
{$title} @@ -292,7 +295,10 @@ eof; echo << - {$file['filename']} + {$file['filename']}
{$title} @@ -321,4 +327,13 @@ if ($total > $viewData['pageSize']) { echo $pagination; } ?> +
+ +
+
\ No newline at end of file diff --git a/www/css/beauty.css b/www/css/beauty.css index 8b8c859..17588d8 100644 --- a/www/css/beauty.css +++ b/www/css/beauty.css @@ -129,6 +129,8 @@ a:link{text-decoration:none} .videotitle{max-width:600px;overflow:hidden;text-wrap:nowrap;text-overflow:ellipsis} .playbtn{width:50px;height:50px;position:absolute;left:50%;top:50%;margin-top:-25px;margin-left:-25px} .duration{position:absolute;left:5px;bottom:5px;background-color:#222;padding:0 3px;opacity:0.7;border-radius:3px;font-size:12px;color:#FFF} +.video_previewer{display:none;position:fixed;right:4px;bottom:4px;width:200px;height:112px;overflow:hidden;z-index:1000} + .mt-2{margin-top:2em} .mr-1{margin-right:1em} diff --git a/www/js/beauty.js b/www/js/beauty.js index 5344b41..1358b81 100644 --- a/www/js/beauty.js +++ b/www/js/beauty.js @@ -212,8 +212,62 @@ var formatDuration = function(duration) { return str; }; +//自动为列表页视频生成封面图并保存 +var noSnapVideos = []; +if ($('#pr-player').length > 0 && typeof(videojs) != 'undefined') { + var myPlayer = videojs('pr-player', { + controls: false, + autoplay: false, + muted: true, + preload: 'auto' + }); + + var mc_video_id = ''; + var tryToGetVideoSnapshot = function() { + if (noSnapVideos.length == 0) {return false;} + + var videoItem = noSnapVideos.pop(); + mc_video_id = videoItem.id; + + console.log(mc_video_id, videoItem.url); + try { + myPlayer.src(videoItem.url); + myPlayer.play(); + }catch(err){ + console.error('自动生成视频封面图失败', err); + } + }; + + myPlayer.on('playing', function() { + myPlayer.pause(); + + if (typeof(mc_video_id) != 'undefined' && mc_video_id) { + var height = myPlayer.videoHeight(), width = myPlayer.videoWidth(), + aspect = height / width; + var canvas = document.createElement('canvas'); + var video = $('video.vjs-tech').get(0); + + canvas.width = Math.ceil(360/aspect); + canvas.height = 360; //360p + + var ctx = canvas.getContext('2d'); + ctx.drawImage( video, 0, 0, canvas.width, canvas.height ); + + var snapshotImg = canvas.toDataURL('image/jpeg'); + saveVideoMeta(mc_video_id, { + duration: myPlayer.duration(), + snapshot: snapshotImg + }); + + tryToGetVideoSnapshot(); //go next + } + }); + + setInterval(tryToGetVideoSnapshot, 1000); +} + //视频列表封面图加载 -var getVideoMetaAndShowIt = function(videoId) { +var getVideoMetaAndShowIt = function(videoId, videoUrl) { $.ajax({ url: '/site/videometa', method: 'GET', @@ -223,7 +277,8 @@ var getVideoMetaAndShowIt = function(videoId) { } }).done(function(data) { if (data.code != 1) { - console.warn('视频数据获取失败', data.msg); + console.warn(data.msg); + noSnapVideos.push({id: videoId, url: videoUrl}); }else { $('#poster_'+videoId).attr('src', data.meta.snapshot); $('#poster_'+videoId).parent('a').find('.duration').text(formatDuration(data.meta.duration)); @@ -234,8 +289,9 @@ var getVideoMetaAndShowIt = function(videoId) { }; $('.video-poster').each(function(index, el) { - var videoId = $(el).attr('data-id'); - getVideoMetaAndShowIt(videoId); + var videoId = $(el).attr('data-video-id'), + videoUrl = $(el).attr('data-video-url'); + getVideoMetaAndShowIt(videoId, videoUrl); }); //保存视频数据 @@ -266,7 +322,7 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') { preload: 'auto' }); - myPlayer.one('play', function() { + myPlayer.one('playing', function() { myPlayer.pause(); var height = myPlayer.videoHeight(), width = myPlayer.videoWidth(),