diff --git a/plugin/PlayerSkins/PlayerSkins.php b/plugin/PlayerSkins/PlayerSkins.php index 390efcb4bf..807926a8ce 100644 --- a/plugin/PlayerSkins/PlayerSkins.php +++ b/plugin/PlayerSkins/PlayerSkins.php @@ -305,6 +305,11 @@ class PlayerSkins extends PluginAbstract { return $js . $css . $oembed; } + static function showAutoplay(){ + $obj = AVideoPlugin::getDataObject('PlayerSkins'); + return !isLive() && $obj->showShareAutoplay && isVideoPlayerHasProgressBar() && empty($obj->forceAlwaysAutoplay) && empty($_REQUEST['hideAutoplaySwitch']); + } + public function getFooterCode() { if (isWebRTC()) { return ''; @@ -338,7 +343,7 @@ class PlayerSkins extends PluginAbstract { $js .= ""; } - if (!isLive() && $obj->showShareAutoplay && isVideoPlayerHasProgressBar() && empty($obj->forceAlwaysAutoplay) && empty($_REQUEST['hideAutoplaySwitch'])) { + if (self::showAutoplay()) { PlayerSkins::getStartPlayerJS(file_get_contents("{$global['systemRootPath']}plugin/PlayerSkins/autoplayButton.js")); } else { if (isLive()) { diff --git a/view/js/script.js b/view/js/script.js index bddbde6f7c..19de110e0c 100644 --- a/view/js/script.js +++ b/view/js/script.js @@ -269,14 +269,14 @@ var pauseIfIsPlayinAdsInterval; async function setPlayerListners() { if (typeof player !== 'undefined') { player.on('pause', function () { - clearTimeout(promisePlayTimeout); + cancelAllPlaybackTimeouts(); //console.log("setPlayerListners: pause"); //userIsControling = true; clearInterval(pauseIfIsPlayinAdsInterval); }); player.on('play', function () { isTryingToPlay = false; - clearTimeout(promisePlayTimeout); + cancelAllPlaybackTimeouts(); if (startCurrentTime) { setTimeout(function () { setCurrentTime(startCurrentTime); @@ -369,7 +369,7 @@ function reloadAds() { setTimeout(function () { isReloadingAds = false; }, 500); - clearTimeout(_reloadAdsTimeout); + cancelAllPlaybackTimeouts(); //console.log('reloadAds '); if (playerIsReady() && player.ima) { try { @@ -571,7 +571,7 @@ var isTryingToPlay = false; var promisePlaytryNetworkFailTimeout; function playerPlay(currentTime) { isTryingToPlay = true; - clearTimeout(playerPlayTimeout); + cancelAllPlaybackTimeouts(); if (playerIsPlayingAds()) { return false; } @@ -631,7 +631,7 @@ function playerPlay(currentTime) { promisePlaytry = 20; promisePlaytryNetworkFail++; //console.log("playerPlay: Network error detected, trying again", promisePlaytryNetworkFail); - clearTimeout(promisePlaytryNetworkFailTimeout); + cancelAllPlaybackTimeouts(); promisePlaytryNetworkFailTimeout = setTimeout(function () { player.src(player.currentSources()); userIsControling = false; @@ -705,7 +705,7 @@ function showUnmutePopup() { } function tryToPlay(currentTime) { - clearTimeout(promisePlayTimeout); + cancelAllPlaybackTimeouts(); promisePlayTimeout = setTimeout(function () { if (player.paused()) { playerPlayTimeout = setTimeout(function () { @@ -807,6 +807,15 @@ function playerPlayIfAutoPlay(currentTime) { return false; } +function cancelAllPlaybackTimeouts(){ + clearTimeout(playerPlayTimeout); + clearTimeout(promisePlayTimeout); + clearTimeout(promisePlaytryNetworkFailTimeout); + clearTimeout(_reloadAdsTimeout); + clearTimeout(videoJSRecreateSourcesTimeout); + clearTimeout(setPlayerLoopSetTimeout); +} + function playerPlayMutedIfAutoPlay(currentTime) { if (isWebRTC()) { return false; @@ -923,7 +932,7 @@ async function tooglePlayerLoop() { var setPlayerLoopSetTimeout; async function setPlayerLoop(loop) { - clearTimeout(setPlayerLoopSetTimeout); + cancelAllPlaybackTimeouts(); if (typeof player === 'undefined' && $('#mainVideo').length) { setPlayerLoopSetTimeout = setTimeout(function () { setPlayerLoop(loop) @@ -3094,7 +3103,7 @@ function fixAdSize() { */ var videoJSRecreateSourcesTimeout; async function videoJSRecreateSources(defaultSource) { - clearTimeout(videoJSRecreateSourcesTimeout); + cancelAllPlaybackTimeouts(); if (empty(player) || empty(player.options_)) { videoJSRecreateSourcesTimeout = setTimeout(function () { videoJSRecreateSources(defaultSource); diff --git a/view/modeYoutubeBottomRight.php b/view/modeYoutubeBottomRight.php index ec06245ff2..2cc3e43962 100644 --- a/view/modeYoutubeBottomRight.php +++ b/view/modeYoutubeBottomRight.php @@ -51,7 +51,7 @@ if (!empty($playlist_id)) { +} elseif (!empty($autoPlayVideo) && PlayerSkins::showAutoplay()) { ?>