mirror of
https://github.com/goodtube4u/goodtube.git
synced 2025-11-22 10:16:11 +00:00
Syncing fix, stops detection
This commit is contained in:
26
goodtube.js
26
goodtube.js
@@ -1345,18 +1345,20 @@
|
||||
|
||||
// If we found the video element
|
||||
if (youtubeVideoElement) {
|
||||
// Sync the current time
|
||||
youtubeVideoElement.currentTime = parseFloat(event.data.replace('goodTube_syncMainPlayer_', ''));
|
||||
// Parse the data
|
||||
let bits = event.data.replace('goodTube_syncMainPlayer_', '').split('_');
|
||||
let syncTime = parseFloat(bits[0]);
|
||||
let videoDuration = parseFloat(bits[1]);
|
||||
|
||||
// Set a variable to indicate we're syncing the player (this stops the automatic pausing of all videos)
|
||||
goodTube_syncingPlayer = true;
|
||||
|
||||
// Play for 10ms to make history work via JS
|
||||
// Play the video via HTML
|
||||
youtubeVideoElement.play();
|
||||
youtubeVideoElement.muted = true;
|
||||
youtubeVideoElement.volume = 0;
|
||||
|
||||
// Play for 10ms to make history work via the frame API
|
||||
// Play the video via the frame API
|
||||
let youtubeFrameApi = document.querySelector('#movie_player');
|
||||
if (youtubeFrameApi) {
|
||||
if (typeof youtubeFrameApi.playVideo === 'function') {
|
||||
@@ -1372,10 +1374,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
// After 10ms stop syncing (and let the pause actions handle the pausing)
|
||||
setTimeout(() => {
|
||||
goodTube_syncingPlayer = false;
|
||||
}, 10);
|
||||
// Make sure the durations match (we do NOT want to touch this if an ad is playing)
|
||||
if (videoDuration === youtubeVideoElement.duration) {
|
||||
// Sync the current time
|
||||
youtubeVideoElement.currentTime = syncTime;
|
||||
|
||||
// After 10ms stop syncing (and let the pause actions handle the pausing)
|
||||
setTimeout(() => {
|
||||
goodTube_syncingPlayer = false;
|
||||
}, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2754,7 +2762,7 @@
|
||||
let videoElement = document.querySelector('video');
|
||||
|
||||
if (videoElement) {
|
||||
window.top.postMessage('goodTube_syncMainPlayer_' + videoElement.currentTime, '*');
|
||||
window.top.postMessage('goodTube_syncMainPlayer_' + videoElement.currentTime + '_' + videoElement.duration, '*');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user