1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-06 03:50:04 +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; 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() { public function getFooterCode() {
if (isWebRTC()) { if (isWebRTC()) {
return ''; return '';
@ -338,7 +343,7 @@ class PlayerSkins extends PluginAbstract {
$js .= "<script>function tooglePlayersocial(){showSharing{$social['id']}();}</script>"; $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")); PlayerSkins::getStartPlayerJS(file_get_contents("{$global['systemRootPath']}plugin/PlayerSkins/autoplayButton.js"));
} else { } else {
if (isLive()) { if (isLive()) {

View file

@ -269,14 +269,14 @@ var pauseIfIsPlayinAdsInterval;
async function setPlayerListners() { async function setPlayerListners() {
if (typeof player !== 'undefined') { if (typeof player !== 'undefined') {
player.on('pause', function () { player.on('pause', function () {
clearTimeout(promisePlayTimeout); cancelAllPlaybackTimeouts();
//console.log("setPlayerListners: pause"); //console.log("setPlayerListners: pause");
//userIsControling = true; //userIsControling = true;
clearInterval(pauseIfIsPlayinAdsInterval); clearInterval(pauseIfIsPlayinAdsInterval);
}); });
player.on('play', function () { player.on('play', function () {
isTryingToPlay = false; isTryingToPlay = false;
clearTimeout(promisePlayTimeout); cancelAllPlaybackTimeouts();
if (startCurrentTime) { if (startCurrentTime) {
setTimeout(function () { setTimeout(function () {
setCurrentTime(startCurrentTime); setCurrentTime(startCurrentTime);
@ -369,7 +369,7 @@ function reloadAds() {
setTimeout(function () { setTimeout(function () {
isReloadingAds = false; isReloadingAds = false;
}, 500); }, 500);
clearTimeout(_reloadAdsTimeout); cancelAllPlaybackTimeouts();
//console.log('reloadAds '); //console.log('reloadAds ');
if (playerIsReady() && player.ima) { if (playerIsReady() && player.ima) {
try { try {
@ -571,7 +571,7 @@ var isTryingToPlay = false;
var promisePlaytryNetworkFailTimeout; var promisePlaytryNetworkFailTimeout;
function playerPlay(currentTime) { function playerPlay(currentTime) {
isTryingToPlay = true; isTryingToPlay = true;
clearTimeout(playerPlayTimeout); cancelAllPlaybackTimeouts();
if (playerIsPlayingAds()) { if (playerIsPlayingAds()) {
return false; return false;
} }
@ -631,7 +631,7 @@ function playerPlay(currentTime) {
promisePlaytry = 20; promisePlaytry = 20;
promisePlaytryNetworkFail++; promisePlaytryNetworkFail++;
//console.log("playerPlay: Network error detected, trying again", promisePlaytryNetworkFail); //console.log("playerPlay: Network error detected, trying again", promisePlaytryNetworkFail);
clearTimeout(promisePlaytryNetworkFailTimeout); cancelAllPlaybackTimeouts();
promisePlaytryNetworkFailTimeout = setTimeout(function () { promisePlaytryNetworkFailTimeout = setTimeout(function () {
player.src(player.currentSources()); player.src(player.currentSources());
userIsControling = false; userIsControling = false;
@ -705,7 +705,7 @@ function showUnmutePopup() {
} }
function tryToPlay(currentTime) { function tryToPlay(currentTime) {
clearTimeout(promisePlayTimeout); cancelAllPlaybackTimeouts();
promisePlayTimeout = setTimeout(function () { promisePlayTimeout = setTimeout(function () {
if (player.paused()) { if (player.paused()) {
playerPlayTimeout = setTimeout(function () { playerPlayTimeout = setTimeout(function () {
@ -807,6 +807,15 @@ function playerPlayIfAutoPlay(currentTime) {
return false; return false;
} }
function cancelAllPlaybackTimeouts(){
clearTimeout(playerPlayTimeout);
clearTimeout(promisePlayTimeout);
clearTimeout(promisePlaytryNetworkFailTimeout);
clearTimeout(_reloadAdsTimeout);
clearTimeout(videoJSRecreateSourcesTimeout);
clearTimeout(setPlayerLoopSetTimeout);
}
function playerPlayMutedIfAutoPlay(currentTime) { function playerPlayMutedIfAutoPlay(currentTime) {
if (isWebRTC()) { if (isWebRTC()) {
return false; return false;
@ -923,7 +932,7 @@ async function tooglePlayerLoop() {
var setPlayerLoopSetTimeout; var setPlayerLoopSetTimeout;
async function setPlayerLoop(loop) { async function setPlayerLoop(loop) {
clearTimeout(setPlayerLoopSetTimeout); cancelAllPlaybackTimeouts();
if (typeof player === 'undefined' && $('#mainVideo').length) { if (typeof player === 'undefined' && $('#mainVideo').length) {
setPlayerLoopSetTimeout = setTimeout(function () { setPlayerLoopSetTimeout = setTimeout(function () {
setPlayerLoop(loop) setPlayerLoop(loop)
@ -3094,7 +3103,7 @@ function fixAdSize() {
*/ */
var videoJSRecreateSourcesTimeout; var videoJSRecreateSourcesTimeout;
async function videoJSRecreateSources(defaultSource) { async function videoJSRecreateSources(defaultSource) {
clearTimeout(videoJSRecreateSourcesTimeout); cancelAllPlaybackTimeouts();
if (empty(player) || empty(player.options_)) { if (empty(player) || empty(player.options_)) {
videoJSRecreateSourcesTimeout = setTimeout(function () { videoJSRecreateSourcesTimeout = setTimeout(function () {
videoJSRecreateSources(defaultSource); videoJSRecreateSources(defaultSource);

View file

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