1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 09:49:28 +02:00

Autoplay fix

This commit is contained in:
Daniel Neto 2023-08-14 14:30:04 -03:00
parent 18a34dabac
commit 5ea6359a97
3 changed files with 24 additions and 10 deletions

View file

@ -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 .= "<script>function tooglePlayersocial(){showSharing{$social['id']}();}</script>";
}
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()) {

View file

@ -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);

View file

@ -51,7 +51,7 @@ if (!empty($playlist_id)) {
</span>
</div>
<?php
} elseif (!empty($autoPlayVideo)) { ?>
} elseif (!empty($autoPlayVideo) && PlayerSkins::showAutoplay()) { ?>
<div class="row">
<div class="col-lg-12 col-sm-12 col-xs-12 autoplay text-muted" style="margin: 10px 0;">
<strong><?php echo __("Up Next"); ?></strong>