mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 09:49:28 +02:00
parent
da9411e231
commit
c245e4525a
1 changed files with 31 additions and 22 deletions
|
@ -473,38 +473,47 @@ function inIframe() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var promisePlayTimeout;
|
||||||
|
var promisePlay;
|
||||||
function playerPlay(currentTime) {
|
function playerPlay(currentTime) {
|
||||||
if (typeof player === 'undefined') {
|
if (typeof player !== 'undefined') {
|
||||||
if(currentTime){
|
if (currentTime) {
|
||||||
player.currentTime(currentTime);
|
player.currentTime(currentTime);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
var promise = player.play();
|
console.log("playerPlay: Trying to play");
|
||||||
|
promisePlay = player.play();
|
||||||
if (promise !== undefined) {
|
if (promisePlay !== undefined) {
|
||||||
promise.then(_ => {
|
promisePlayTimeout = setTimeout(function () {
|
||||||
// Autoplay started!
|
console.log("playerPlay: Promise is Pending, try again");
|
||||||
}).catch(error => {
|
playerPlay(currentTime);
|
||||||
|
}, 1000);
|
||||||
|
console.log("playerPlay: promise found");
|
||||||
|
console.log(promisePlay);
|
||||||
|
promisePlay.then(function () {
|
||||||
|
console.log("playerPlay: Autoplay started");
|
||||||
|
clearTimeout(promisePlayTimeout);
|
||||||
|
}).catch(function (error) {
|
||||||
|
console.log("playerPlay: Autoplay was prevented, trying to mute and play");
|
||||||
// Show something in the UI that the video is muted
|
// Show something in the UI that the video is muted
|
||||||
player.muted(true);
|
player.muted(true);
|
||||||
player.play();
|
playerPlay(currentTime);
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
promisePlayTimeout = setTimeout(function () {
|
||||||
|
if (player.paused()) {
|
||||||
|
console.log("playerPlay: promise Undefined");
|
||||||
|
playerPlay(currentTime);
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.log("playerPlay: We could not autoplay, trying again in 1 second");
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
var promise = player.play();
|
playerPlay(currentTime);
|
||||||
|
|
||||||
if (promise !== undefined) {
|
|
||||||
promise.then(_ => {
|
|
||||||
// Autoplay started!
|
|
||||||
}).catch(error => {
|
|
||||||
// Show something in the UI that the video is muted
|
|
||||||
player.muted(true);
|
|
||||||
player.play();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
console.log("playerPlay: Player is Undefined");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue