Browse Source

improve manual screenshot create

master
filesite 4 months ago
parent
commit
792ef44871
  1. 17
      themes/beauty/controller/SiteController.php
  2. 31
      www/js/beauty.js

17
themes/beauty/controller/SiteController.php

@ -283,20 +283,33 @@ Class SiteController extends Controller {
return $this->renderJson(compact('code', 'msg', 'meta')); return $this->renderJson(compact('code', 'msg', 'meta'));
} }
//保存视频meta数据到缓存 //保存视频meta数据到缓存,支持手动生成
public function actionSavevideometa() { public function actionSavevideometa() {
$code = 0; $code = 0;
$msg = 'OK'; $msg = 'OK';
$videoId = $this->post('id', ''); $videoId = $this->post('id', '');
$metaData = $this->post('meta', ''); $metaData = $this->post('meta', '');
$manual = $this->post('manual', 0);
if (empty($videoId) || empty($metaData)) { if (empty($videoId) || empty($metaData)) {
$code = 0; $code = 0;
$msg = '参数不能为空'; $msg = '参数不能为空';
}else { }else {
$cacheKey = $this->getCacheKey($videoId, 'vmeta'); $cacheKey = $this->getCacheKey($videoId, 'vmeta');
$cacheSubDir = 'video'; $cacheSubDir = 'video';
$saved = Common::saveCacheToFile($cacheKey, $metaData, $cacheSubDir); $saved = true;
if (!empty($manual)) {
$metaData['manual'] = 1;
$saved = Common::saveCacheToFile($cacheKey, $metaData, $cacheSubDir);
}else {
$expireSeconds = 86400*30; //有效期30天
$cachedData = Common::getCacheFromFile($cacheKey, $expireSeconds, $cacheSubDir);
if (empty($cachedData) || empty($cachedData['manual'])) {
$saved = Common::saveCacheToFile($cacheKey, $metaData, $cacheSubDir);
}
}
if ($saved !== false) { if ($saved !== false) {
$code = 1; $code = 1;
} }

31
www/js/beauty.js

@ -304,15 +304,20 @@ $('.video-poster').each(function(index, el) {
}); });
//保存视频数据 //保存视频数据
var saveVideoMeta = function(videoId, metaData) { var saveVideoMeta = function(videoId, metaData, manual) {
var params = {
id: videoId,
meta: metaData
};
if (typeof(manual) != 'undefined' && manual) {
params.manual = 1;
}
$.ajax({ $.ajax({
url: '/site/savevideometa', url: '/site/savevideometa',
method: 'POST', method: 'POST',
dataType: 'json', dataType: 'json',
data: { data: params
id: videoId,
meta: metaData
}
}).done(function(data) { }).done(function(data) {
if (data.code != 1) { if (data.code != 1) {
console.warn('视频数据保存失败', data.msg); console.warn('视频数据保存失败', data.msg);
@ -331,7 +336,7 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') {
preload: 'auto' preload: 'auto'
}); });
var takeScreenshot = function() { var takeScreenshot = function(manual) {
//myPlayer.pause(); //myPlayer.pause();
var height = myPlayer.videoHeight(), width = myPlayer.videoWidth(), var height = myPlayer.videoHeight(), width = myPlayer.videoWidth(),
@ -351,7 +356,7 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') {
saveVideoMeta($('video.vjs-tech').attr('data-id'), { saveVideoMeta($('video.vjs-tech').attr('data-id'), {
duration: duration, duration: duration,
snapshot: snapshotImg snapshot: snapshotImg
}); }, manual);
} }
//myPlayer.play(); //myPlayer.play();
@ -371,7 +376,15 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') {
setTimeout(takeScreenshot, screenshot_start); setTimeout(takeScreenshot, screenshot_start);
}); });
$('.btn-snapshot').click(function() { $('.btn-snapshot').click(function(e) {
takeScreenshot(); var clickedBtn = $(e.target);
clickedBtn.prop('disabled', true);
var manual = 1;
takeScreenshot(manual);
setTimeout(function() {
clickedBtn.prop('disabled', false);
}, 3000);
}); });
} }
Loading…
Cancel
Save