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 { @@ -283,20 +283,33 @@ Class SiteController extends Controller {
return $this->renderJson(compact('code', 'msg', 'meta'));
}
//保存视频meta数据到缓存
//保存视频meta数据到缓存,支持手动生成
public function actionSavevideometa() {
$code = 0;
$msg = 'OK';
$videoId = $this->post('id', '');
$metaData = $this->post('meta', '');
$manual = $this->post('manual', 0);
if (empty($videoId) || empty($metaData)) {
$code = 0;
$msg = '参数不能为空';
}else {
$cacheKey = $this->getCacheKey($videoId, 'vmeta');
$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) {
$code = 1;
}

31
www/js/beauty.js

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