mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 01:39:24 +02:00
Fix playback start
This commit is contained in:
parent
ff20a1b754
commit
5e6e50f9ad
10 changed files with 111 additions and 95 deletions
|
@ -669,7 +669,7 @@ class Category
|
|||
global $global, $config;
|
||||
$sql = "SELECT count(id) as total FROM categories WHERE parentId=? AND id!=? ";
|
||||
|
||||
$res = sqlDAL::readSql($sql, "i", [$parentId]);
|
||||
$res = sqlDAL::readSql($sql, "ii", [$parentId, $parentId]);
|
||||
$result = sqlDAL::fetchAssoc($res);
|
||||
sqlDAL::close($res);
|
||||
if ($res) {
|
||||
|
|
|
@ -335,7 +335,7 @@ function linkifyTimestamps($text) {
|
|||
}
|
||||
|
||||
// Return the clickable link
|
||||
return "<a href='javascript:void(0)' onclick=\"player.currentTime($seconds);\">$timestamp</a>";
|
||||
return "<a href='javascript:void(0)' onclick=\"console.log('objects-functionsSecurity.php player.currentTime');player.currentTime($seconds);\">$timestamp</a>";
|
||||
};
|
||||
|
||||
// Replace timestamps with links
|
||||
|
|
|
@ -231,6 +231,7 @@
|
|||
|
||||
if (!preventDefault) {
|
||||
var key = this.getAttribute('data-marker-key');
|
||||
console.log('currentTime video markers');
|
||||
player.currentTime(setting.markerTip.time(markersMap[key]));
|
||||
}
|
||||
});
|
||||
|
@ -459,6 +460,7 @@
|
|||
for (var i = 0; i < markersList.length; i++) {
|
||||
var markerTime = setting.markerTip.time(markersList[i]);
|
||||
if (markerTime > currentTime) {
|
||||
console.log('currentTime video markers 2');
|
||||
player.currentTime(markerTime);
|
||||
break;
|
||||
}
|
||||
|
@ -471,6 +473,7 @@
|
|||
var markerTime = setting.markerTip.time(markersList[i]);
|
||||
// add a threshold
|
||||
if (markerTime + 0.5 < currentTime) {
|
||||
console.log('currentTime video markers 3');
|
||||
player.currentTime(markerTime);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -30,9 +30,11 @@ this.el().addEventListener('touchend', function(event) {
|
|||
var touchX = event.changedTouches[0].clientX;
|
||||
var videoWidth = player.el().clientWidth;
|
||||
if (touchX < videoWidth / 2) {
|
||||
console.log('currentTime hot key 1');
|
||||
// Double tap on the left half - rewind
|
||||
player.currentTime(player.currentTime() - 10);
|
||||
} else {
|
||||
console.log('currentTime hot key 2');
|
||||
// Double tap on the right half - forward
|
||||
player.currentTime(player.currentTime() + 10);
|
||||
}
|
||||
|
|
|
@ -11,9 +11,11 @@ window.addEventListener('message', function(event) {
|
|||
}
|
||||
break;
|
||||
case 'rewind':
|
||||
console.log('currentTime hot key rewind');
|
||||
player.currentTime(player.currentTime() - 10);
|
||||
break;
|
||||
case 'forward':
|
||||
console.log('currentTime hot key forward');
|
||||
player.currentTime(player.currentTime() + 10);
|
||||
break;
|
||||
case 'volumeUp':
|
||||
|
|
|
@ -203,6 +203,7 @@ echo AVideoPlugin::afterVideoJS();
|
|||
return false;
|
||||
});
|
||||
|
||||
console.log('currentTime player 1');
|
||||
player.currentTime(playerPlaylist[0].videoStartSeconds);
|
||||
$("#modeYoutubeBottomContent").load("<?php echo $global['webSiteRootURL']; ?>view/modeYoutubeBottom.php?videos_id=" + playerPlaylist[0].videos_id);
|
||||
$(".vjs-playlist-item ").click(function() {
|
||||
|
@ -215,6 +216,7 @@ echo AVideoPlugin::afterVideoJS();
|
|||
$("#modeYoutubeBottomContent").load("<?php echo $global['webSiteRootURL']; ?>view/modeYoutubeBottom.php?videos_id=" + playerPlaylist[index].videos_id);
|
||||
if (playerPlaylist[index] && playerPlaylist[index].videoStartSeconds) {
|
||||
setTimeout(function() {
|
||||
console.log('currentTime player 2');
|
||||
player.currentTime(playerPlaylist[index].videoStartSeconds);
|
||||
}, 500);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
// Queue to track skipped ads
|
||||
let skippedAdsQueue = [];
|
||||
|
||||
// Array to store scheduled ad times
|
||||
let scheduledAdTimes = [];
|
||||
|
||||
// Dynamic interval for live ads
|
||||
let liveAdInterval = null;
|
||||
|
||||
// Fetch and parse VMAP
|
||||
if (typeof _adTagUrl === 'string') {
|
||||
fetch(_adTagUrl)
|
||||
|
@ -14,12 +20,12 @@ if (typeof _adTagUrl === 'string') {
|
|||
console.log('timeOffset found', timeOffset);
|
||||
|
||||
if (timeOffset === 'start') {
|
||||
scheduleAd(0);
|
||||
scheduledAdTimes.push(0);
|
||||
} else if (timeOffset === 'end') {
|
||||
scheduleAdAtEnd();
|
||||
scheduledAdTimes.push('end');
|
||||
} else if (timeOffset) {
|
||||
var seconds = convertTimeOffsetToSeconds(timeOffset);
|
||||
scheduleAd(seconds);
|
||||
scheduledAdTimes.push(seconds);
|
||||
}
|
||||
});
|
||||
})
|
||||
|
@ -39,95 +45,95 @@ function convertTimeOffsetToSeconds(timeOffset) {
|
|||
// Ensure ad display container is initialized on mobile
|
||||
function initializeAdContainer() {
|
||||
if (player.ima && typeof player.ima.initializeAdDisplayContainer === "function") {
|
||||
console.log(`scheduleAd: initializeAdDisplayContainer`);
|
||||
console.log(`initializeAdContainer: Initializing ad container`);
|
||||
player.ima.initializeAdDisplayContainer();
|
||||
}
|
||||
}
|
||||
|
||||
// Schedule ad playback
|
||||
// Function to dynamically schedule ads
|
||||
function scheduleAd(seconds) {
|
||||
if (seconds > 5) {
|
||||
for (let index = 5; index > 0; index--) {
|
||||
setTimeout(() => {
|
||||
console.log(`scheduleAd: Ad will play in ${index} seconds at ${seconds} seconds`);
|
||||
}, (seconds - index) * 1000);
|
||||
if (player.liveTracker && player.liveTracker.isLive()) {
|
||||
liveAdInterval = seconds; // Set live ad interval dynamically
|
||||
console.log(`Live ad interval set to ${seconds} seconds`);
|
||||
setupLiveAdInterval();
|
||||
} else {
|
||||
scheduledAdTimes.push(seconds);
|
||||
}
|
||||
}
|
||||
setTimeout(() => {
|
||||
console.log(`scheduleAd: Checking playback state for ad at ${seconds} seconds`);
|
||||
if (!player.paused()) {
|
||||
console.log(`scheduleAd: Triggering ad at ${seconds} seconds`);
|
||||
try {
|
||||
// Ensure the ad container is ready (for mobile)
|
||||
initializeAdContainer();
|
||||
|
||||
// Request and play ads
|
||||
// Function to set up live ad interval
|
||||
function setupLiveAdInterval() {
|
||||
if (liveAdInterval && player.liveTracker && player.liveTracker.isLive()) {
|
||||
setInterval(() => {
|
||||
console.log(`Triggering live ad every ${liveAdInterval} seconds`);
|
||||
try {
|
||||
initializeAdContainer();
|
||||
player.ima.requestAds();
|
||||
} catch (error) {
|
||||
console.error(`scheduleAd: Error while triggering ad: ${error.message}`);
|
||||
console.error(`Error triggering live ad: ${error.message}`);
|
||||
}
|
||||
} else {
|
||||
if(checkIfAdIsPlaying()){
|
||||
console.log(`scheduleAd: ad is already playing, skipping ad at ${seconds} seconds`);
|
||||
}else{
|
||||
|
||||
skippedAdsQueue.push(() => {
|
||||
console.log('Playing skipped ad at the end of the video');
|
||||
initializeAdContainer();
|
||||
player.ima.requestAds();
|
||||
});
|
||||
console.log(`scheduleAd: Video is paused, skipping ad at ${seconds} seconds`);
|
||||
}
|
||||
// Add logic to handle skipped ads if needed
|
||||
}
|
||||
}, seconds * 1000);
|
||||
}
|
||||
|
||||
// Schedule ad at the end of the video
|
||||
function scheduleAdAtEnd() {
|
||||
player.on('timeupdate', function handleTimeUpdate() {
|
||||
const remainingTime = player.duration() - player.currentTime();
|
||||
|
||||
// Countdown messages for the ad
|
||||
if (remainingTime <= 10 && remainingTime > 5) {
|
||||
const countdown = Math.floor(remainingTime - 5);
|
||||
for (let index = countdown; index > 0; index--) {
|
||||
setTimeout(() => {
|
||||
console.log(`scheduleAdAtEnd: Ad will play in ${index} seconds at the end of the video`);
|
||||
}, (countdown - index) * 1000);
|
||||
}, liveAdInterval * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the ad should be triggered
|
||||
if (remainingTime <= 5) {
|
||||
console.log('scheduleAdAtEnd: Checking playback state for ad at the end of the video');
|
||||
// Function to check and play ads based on current time
|
||||
function checkAndPlayAds() {
|
||||
const currentTime = player.currentTime();
|
||||
scheduledAdTimes = scheduledAdTimes.filter(adTime => {
|
||||
if (adTime === 'end') return true; // Keep the "end" marker for later handling
|
||||
if (currentTime >= adTime) {
|
||||
console.log(`Triggering ad scheduled for ${adTime} seconds`);
|
||||
try {
|
||||
if (!player.paused()) {
|
||||
console.log('scheduleAdAtEnd: Triggering ad at the end of the video');
|
||||
initializeAdContainer();
|
||||
player.ima.requestAds();
|
||||
player.off('timeupdate', handleTimeUpdate); // Remove listener after ad is triggered
|
||||
} else {
|
||||
if (checkIfAdIsPlaying()) {
|
||||
console.log('scheduleAdAtEnd: Ad is already playing, skipping ad at the end of the video');
|
||||
} else {
|
||||
skippedAdsQueue.push(() => {
|
||||
console.log('Playing skipped ad at the end of the video');
|
||||
initializeAdContainer();
|
||||
player.ima.requestAds();
|
||||
});
|
||||
console.log('scheduleAdAtEnd: Video is paused, skipping ad at the end of the video');
|
||||
}
|
||||
player.off('timeupdate', handleTimeUpdate); // Remove listener
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`scheduleAdAtEnd: Error while triggering ad: ${error.message}`);
|
||||
console.error(`Error triggering ad at ${adTime} seconds: ${error.message}`);
|
||||
}
|
||||
return false; // Remove this ad time as it has been triggered
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
// Play skipped ads after the video resumes
|
||||
// Function to check if an ad is playing
|
||||
function checkIfAdIsPlaying() {
|
||||
console.log('Is an ad playing?', isAdPlaying);
|
||||
return isAdPlaying;
|
||||
}
|
||||
|
||||
function fixAdPlaying(){
|
||||
if(isAdPlaying){
|
||||
if (!player.paused()) {
|
||||
console.log('fixAdPlaying: Pausing main video');
|
||||
player.pause(); // Pause the main video
|
||||
}
|
||||
}else{
|
||||
if (player.paused()) {
|
||||
console.log('fixAdPlaying: Resuming main video');
|
||||
player.play(); // Resume the main video
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set up event listener to check ad triggers on time updates
|
||||
player.on('timeupdate', () => {
|
||||
checkAndPlayAds();
|
||||
});
|
||||
|
||||
// Handle ads at the end of the video
|
||||
player.on('ended', () => {
|
||||
if (scheduledAdTimes.includes('end')) {
|
||||
console.log('Playing ad at the end of the video');
|
||||
try {
|
||||
initializeAdContainer();
|
||||
player.ima.requestAds();
|
||||
} catch (error) {
|
||||
console.error(`Error triggering ad at the end of the video: ${error.message}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Play skipped ads when the video resumes
|
||||
player.on('play', () => {
|
||||
while (skippedAdsQueue.length > 0) {
|
||||
const playSkippedAd = skippedAdsQueue.shift();
|
||||
|
@ -135,34 +141,27 @@ player.on('play', () => {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
let isAdPlaying = false;
|
||||
|
||||
// Listen for ad start event
|
||||
player.on('ads-ad-started', () => {
|
||||
isAdPlaying = true;
|
||||
console.log('Ad started playing');
|
||||
fixAdPlaying();
|
||||
});
|
||||
|
||||
// Listen for ad end event
|
||||
// Listen for ad end event to resume the main video
|
||||
player.on('ads-ad-ended', () => {
|
||||
isAdPlaying = false;
|
||||
console.log('Ad finished playing');
|
||||
fixAdPlaying();
|
||||
});
|
||||
|
||||
// Listen for ad error
|
||||
// Listen for ad error and reset playback states if needed
|
||||
player.on('adserror', () => {
|
||||
isAdPlaying = false;
|
||||
console.log('Ad playback encountered an error');
|
||||
console.log('Ad playback encountered an error, resuming main video if paused');
|
||||
fixAdPlaying();
|
||||
});
|
||||
|
||||
// Example usage
|
||||
player.on('ads-manager', function(response) {
|
||||
console.log('Ads manager ready:', response.adsManager);
|
||||
});
|
||||
|
||||
// Function to check if an ad is playing
|
||||
function checkIfAdIsPlaying() {
|
||||
console.log('Is an ad playing?', isAdPlaying);
|
||||
return isAdPlaying;
|
||||
}
|
|
@ -30,10 +30,12 @@ if (empty($MediaMetadata)) {
|
|||
});
|
||||
setActionHandlerIfSupported('seekbackward', function() {
|
||||
/* Code excerpted. */
|
||||
console.log('currentTime mediasession 1');
|
||||
player.currentTime(player.currentTime() - 5);
|
||||
});
|
||||
setActionHandlerIfSupported('seekforward', function() {
|
||||
/* Code excerpted. */
|
||||
console.log('currentTime mediasession 1');
|
||||
player.currentTime(player.currentTime() + 5);
|
||||
});
|
||||
setActionHandlerIfSupported('seekto', function() {
|
||||
|
|
|
@ -22,6 +22,7 @@ function startTrackDisplay() {
|
|||
$('#forwardLayer').remove();
|
||||
});
|
||||
}, 100);
|
||||
console.log('currentTime seek 1');
|
||||
player.currentTime(player.currentTime() + playerSeekForward);
|
||||
} else if (e.offsetX < 0.33 * playerWidth) {
|
||||
$(backLayer).prependTo("#mainVideo");
|
||||
|
@ -31,6 +32,7 @@ function startTrackDisplay() {
|
|||
$('#backLayer').remove();
|
||||
});
|
||||
}, 100);
|
||||
console.log('currentTime seek 2');
|
||||
player.currentTime((player.currentTime() - playerSeekBack) < 0 ? 0 : (player.currentTime() - playerSeekBack));
|
||||
} else {
|
||||
if (player.paused()) {
|
||||
|
|
|
@ -296,6 +296,7 @@ async function lazyImage() {
|
|||
}
|
||||
|
||||
var pauseIfIsPlayinAdsInterval;
|
||||
|
||||
async function setPlayerListners() {
|
||||
if (typeof player !== 'undefined') {
|
||||
player.on('pause', function () {
|
||||
|
@ -307,12 +308,13 @@ async function setPlayerListners() {
|
|||
player.on('play', function () {
|
||||
isTryingToPlay = false;
|
||||
cancelAllPlaybackTimeouts();
|
||||
/* this was messing um the start playback time
|
||||
if (startCurrentTime) {
|
||||
setTimeout(function () {
|
||||
setCurrentTime(startCurrentTime);
|
||||
startCurrentTime = 0;
|
||||
}, 100);
|
||||
}
|
||||
}*/
|
||||
//console.log("setPlayerListners: play");
|
||||
//userIsControling = true;
|
||||
pauseIfIsPlayinAdsInterval = setInterval(function () {
|
||||
|
@ -1109,6 +1111,7 @@ function setCurrentTime(currentTime) {
|
|||
return false; // if is trying to play, only update if the time is greater
|
||||
}
|
||||
}
|
||||
console.trace();
|
||||
console.log("setCurrentTime 1: ", currentTime);
|
||||
player.currentTime(currentTime);
|
||||
initdone = false;
|
||||
|
@ -1121,6 +1124,7 @@ function setCurrentTime(currentTime) {
|
|||
// events: https://www.w3.org/TR/html5/embedded-content-0.html#mediaevents
|
||||
player.on("canplaythrough", function () {
|
||||
if (!initdone) {
|
||||
console.trace();
|
||||
console.log('setCurrentTime canplaythrough', currentTime);
|
||||
player.currentTime(currentTime);
|
||||
initdone = true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue