From b4db41053420be7a80469d380c9d10de49e12705 Mon Sep 17 00:00:00 2001 From: filesite Date: Tue, 30 Jul 2024 09:35:20 +0800 Subject: [PATCH] improve video auto play --- www/js/beauty.js | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/www/js/beauty.js b/www/js/beauty.js index fbdb0b8..36f3db3 100644 --- a/www/js/beauty.js +++ b/www/js/beauty.js @@ -640,6 +640,7 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') { //加载更多视频 var currentPage = $('.othervideos').attr('data-page'), currentVideoId = $('.othervideos').attr('data-id'); + var callback_loadNextPage = null; var getOtherVideos = function(currentPage) { if (_noMoreVideos) {return false;} var videoId = $('.othervideos').attr('data-id'), @@ -669,6 +670,10 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') { getVideoMetaAndShowIt(videoId, videoUrl); }); }, 50); + + if (callback_loadNextPage) { + callback_loadNextPage(data.videos); + } }else { _noMoreVideos = true; console.warn('获取更多视频数据出错啦', data.msg); @@ -681,21 +686,27 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') { getOtherVideos(currentPage); //自动播放 + var playNextVideo = function() { + var nextVideo = moreVideos.shift(); + if (nextVideo.id == currentVideoId && moreVideos.length > 0) { + nextVideo = moreVideos.shift(); + } + + if (nextVideo) { + myPlayer.src(nextVideo.path); + $('.navbar-header .videotitle').text(nextVideo.filename); + } + }; myPlayer.on('ended', function() { var cachedAutoPlayStatus = Cookies.get('autoplay'); if (cachedAutoPlayStatus == 'off') {return false;} if (moreVideos && moreVideos.length > 0) { - var nextVideo = moreVideos.shift(); - if (nextVideo.id == currentVideoId && moreVideos.length > 0) { - nextVideo = moreVideos.shift(); - } - - if (nextVideo) { - myPlayer.src(nextVideo.path); - $('.navbar-header .videotitle').text(nextVideo.filename); - } + playNextVideo(); }else { + callback_loadNextPage = function(videos) { + playNextVideo(); + }; currentPage = parseInt(currentPage) + 1; getOtherVideos(currentPage); }