Browse Source

auto play ready for test

master
filesite 4 months ago
parent
commit
d34b080dcc
  1. 6
      themes/beauty/controller/ListController.php
  2. 117
      www/js/beauty.js

6
themes/beauty/controller/ListController.php

@ -25,7 +25,7 @@ Class ListController extends Controller { @@ -25,7 +25,7 @@ Class ListController extends Controller {
$scanner = new DirScanner();
//根据参数cid获取id对应的目录realpath,从而只扫描这个目录
$cacheSeconds = 3600;
$cacheSeconds = 86400;
$cachedParentData = Common::getCacheFromFile($cacheParentDataId, $cacheSeconds);
if (empty($cachedParentData)) {
return $this->redirect('/');
@ -44,7 +44,7 @@ Class ListController extends Controller { @@ -44,7 +44,7 @@ Class ListController extends Controller {
//优先从缓存读取数据
$maxScanDeep = 0; //最大扫描目录级数
$cacheKey = $this->getCacheKey($cateId, 'tree', $maxScanDeep);
$cachedData = Common::getCacheFromFile($cacheKey);
$cachedData = Common::getCacheFromFile($cacheKey, $cacheSeconds);
if (!empty($cachedData)) {
$dirTree = $cachedData;
$scanner->setTreeData($cachedData);
@ -55,7 +55,7 @@ Class ListController extends Controller { @@ -55,7 +55,7 @@ Class ListController extends Controller {
//优先从缓存读取数据
$cacheKey = $cacheDataId = $this->getCacheKey($cateId, 'data', $maxScanDeep);
$cachedData = Common::getCacheFromFile($cacheKey);
$cachedData = Common::getCacheFromFile($cacheKey, $cacheSeconds);
if (!empty($cachedData)) {
$scanResults = $cachedData;
$scanner->setScanResults($cachedData);

117
www/js/beauty.js

@ -546,6 +546,7 @@ var saveVideoMeta = function(videoId, metaData, manual) { @@ -546,6 +546,7 @@ var saveVideoMeta = function(videoId, metaData, manual) {
};
//视频播放器
var moreVideos = [], _noMoreVideos = false;
if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') {
var myPlayer = videojs('my-player', {
controls: true,
@ -590,6 +591,7 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') { @@ -590,6 +591,7 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') {
setTimeout(takeScreenshot, screenshot_start);
});
//生成封面图
$('.btn-snapshot').click(function(e) {
var clickedBtn = $(e.target);
clickedBtn.prop('disabled', true);
@ -601,22 +603,6 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') { @@ -601,22 +603,6 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') {
clickedBtn.prop('disabled', false);
}, 3000);
});
}
//加载更多视频
if ($('.othervideos').length > 0) {
var videoId = $('.othervideos').attr('data-id'),
cateId = $('.othervideos').attr('data-pid'),
cacheId = $('.othervideos').attr('data-cid'),
currentPage = $('.othervideos').attr('data-page');
var api = '/list/',
params = {
id: cateId,
cid: cacheId,
show: 'video',
dataType: 'video',
page: currentPage
};
var getVideoUrl = function(videoId, videoPath) {
var url = new URL(location.href);
@ -651,28 +637,87 @@ if ($('.othervideos').length > 0) { @@ -651,28 +637,87 @@ if ($('.othervideos').length > 0) {
return html;
};
$.ajax({
url: api,
method: 'GET',
dataType: 'json',
data: params
}).done(function(data) {
//console.log('more videos', data);
if (typeof(data.videos) != 'undefined' && data.videos.length > 0) {
$('.othervideos').html(renderVideos(videoId, data.videos));
setTimeout(function() {
$('.othervideos .video-poster').each(function(index, el) {
var videoId = $(el).attr('data-video-id'),
videoUrl = $(el).attr('data-video-url');
getVideoMetaAndShowIt(videoId, videoUrl);
});
}, 50);
//加载更多视频
var currentPage = $('.othervideos').attr('data-page');
var getOtherVideos = function(currentPage) {
if (_noMoreVideos) {return false;}
var videoId = $('.othervideos').attr('data-id'),
cateId = $('.othervideos').attr('data-pid'),
cacheId = $('.othervideos').attr('data-cid');
var api = '/list/',
params = {
id: cateId,
cid: cacheId,
show: 'video',
dataType: 'video',
page: currentPage
};
$.ajax({
url: api,
method: 'GET',
dataType: 'json',
data: params
}).done(function(data) {
if (typeof(data.videos) != 'undefined' && data.videos.length > 0) {
moreVideos = data.videos;
$('.othervideos').html(renderVideos(videoId, data.videos));
setTimeout(function() {
$('.othervideos .video-poster').each(function(index, el) {
var videoId = $(el).attr('data-video-id'),
videoUrl = $(el).attr('data-video-url');
getVideoMetaAndShowIt(videoId, videoUrl);
});
}, 50);
}else {
_noMoreVideos = true;
console.warn('获取更多视频数据出错啦', data.msg);
}
}).fail(function(jqXHR, textStatus, errorThrown) {
console.error('获取更多视频数据失败,错误信息:' + errorThrown);
});
};
getOtherVideos(currentPage);
//自动播放
myPlayer.on('ended', function() {
var cachedAutoPlayStatus = Cookies.get('autoplay');
if (cachedAutoPlayStatus == 'off') {return false;}
if (moreVideos && moreVideos.length > 0) {
var nextVideo = moreVideos.shift();
myPlayer.src(nextVideo.path);
}else {
//_noMoreData = true;
console.warn('获取更多视频数据出错啦', data.msg);
currentPage = parseInt(currentPage) + 1;
getOtherVideos(currentPage);
}
}).fail(function(jqXHR, textStatus, errorThrown) {
console.error('获取更多视频数据失败,错误信息:' + errorThrown);
});
var switchAutoPlayBtns = function(status) {
var cookieKey = 'autoplay';
if (status == 'on') {
$('.autoplay_disabled').removeClass('btn-primary');
$('.autoplay_enabled').addClass('btn-primary');
Cookies.set(cookieKey, 'on', { expires: 7 });
}else {
$('.autoplay_enabled').removeClass('btn-primary');
$('.autoplay_disabled').addClass('btn-primary');
Cookies.set(cookieKey, 'off', { expires: 7 });
}
$('#my-player').focus();
};
var cachedAutoPlayStatus = Cookies.get('autoplay');
if (cachedAutoPlayStatus == 'off') {
$('.autoplay_enabled').removeClass('btn-primary');
$('.autoplay_disabled').addClass('btn-primary');
}
$('.autoplay_disabled').click(function() {
switchAutoPlayBtns('off');
});
$('.autoplay_enabled').click(function() {
switchAutoPlayBtns('on');
});
}

Loading…
Cancel
Save