From 5b908857160031bbd52ddf9584f88cec958b4fe2 Mon Sep 17 00:00:00 2001 From: filesite Date: Sat, 10 Aug 2024 08:15:09 +0800 Subject: [PATCH] video play loop for all pages --- themes/beauty/controller/SiteController.php | 3 ++- themes/beauty/views/site/index.php | 2 +- themes/beauty/views/site/player.php | 1 + www/js/beauty.js | 19 +++++++++++++------ 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/themes/beauty/controller/SiteController.php b/themes/beauty/controller/SiteController.php index a2e3df9..50d0271 100644 --- a/themes/beauty/controller/SiteController.php +++ b/themes/beauty/controller/SiteController.php @@ -431,6 +431,7 @@ Class SiteController extends Controller { $cateId = $this->get('pid', ''); $cacheParentDataId = $this->get('cid', ''); $page = $this->get('page', 1); + $pageSize = $this->get('limit', 24); if (empty($videoUrl) || empty($videoId) || empty($cateId) || empty($cacheParentDataId)) { throw new Exception("缺少参数!", 403); @@ -456,7 +457,7 @@ Class SiteController extends Controller { $viewName = 'player'; $params = compact( 'videoUrl', 'videoId', 'videoFilename', - 'cateId', 'cacheParentDataId', 'page', + 'cateId', 'cacheParentDataId', 'page', 'pageSize', 'copyright' ); return $this->render($viewName, $params, $pageTitle); diff --git a/themes/beauty/views/site/index.php b/themes/beauty/views/site/index.php index 54b6946..e432785 100644 --- a/themes/beauty/views/site/index.php +++ b/themes/beauty/views/site/index.php @@ -320,7 +320,7 @@ eof; $videoUrl = urlencode($file['path']); $linkUrl = "/site/player?id={$file['id']}&pid={$file['pid']}&cid={$viewData['cacheDataId']}&url={$videoUrl}"; if ($viewData['showType'] == 'video') { - $linkUrl .= "&page={$viewData['page']}"; + $linkUrl .= "&page={$viewData['page']}&limit={$viewData['pageSize']}"; } echo <<其它视频 diff --git a/www/js/beauty.js b/www/js/beauty.js index 36f3db3..300d334 100644 --- a/www/js/beauty.js +++ b/www/js/beauty.js @@ -639,9 +639,10 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') { //加载更多视频 var currentPage = $('.othervideos').attr('data-page'), + currentPageSize = $('.othervideos').attr('data-page-size'), currentVideoId = $('.othervideos').attr('data-id'); var callback_loadNextPage = null; - var getOtherVideos = function(currentPage) { + var getOtherVideos = function() { if (_noMoreVideos) {return false;} var videoId = $('.othervideos').attr('data-id'), cateId = $('.othervideos').attr('data-pid'), @@ -652,7 +653,8 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') { cid: cacheId, show: 'video', dataType: 'video', - page: currentPage + page: currentPage, + limit: currentPageSize }; $.ajax({ url: api, @@ -675,15 +677,20 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') { callback_loadNextPage(data.videos); } }else { - _noMoreVideos = true; - console.warn('获取更多视频数据出错啦', data.msg); + if (currentPage > 1) { + currentPage = 1; //重新从第一页循环播放 + getOtherVideos(); + }else { + _noMoreVideos = true; + console.warn('获取更多视频数据出错啦', data.msg); + } } }).fail(function(jqXHR, textStatus, errorThrown) { console.error('获取更多视频数据失败,错误信息:' + errorThrown); }); }; - getOtherVideos(currentPage); + getOtherVideos(); //自动播放 var playNextVideo = function() { @@ -708,7 +715,7 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') { playNextVideo(); }; currentPage = parseInt(currentPage) + 1; - getOtherVideos(currentPage); + getOtherVideos(); } });