Fix seek to a new time in youtube video does not work when pause action happens instantly after it

This commit is contained in:
Hadi Nategh 2022-05-09 11:27:59 +02:00
parent 126bab8146
commit 58077a60f1
2 changed files with 19 additions and 2 deletions

View File

@ -289,10 +289,18 @@ var et2_video = /** @class */ (function (_super) {
* Pause video
*/
et2_video.prototype.pause_video = function () {
var _this = this;
if (this._isYoutube()) {
if (this.youtube.pauseVideo) {
this.youtube.pauseVideo();
this.currentTime(this.youtube.getCurrentTime());
if (this.youtube.getCurrentTime() != this._currentTime) {
// give it a chance to get actual current time ready otherwise we would still get the previous time
// unfortunately we need to rely on a timeout as the youtube seekTo not returning any promise to wait for.
setTimeout(function (_) { _this.currentTime(_this.youtube.getCurrentTime()); }, 500);
}
else {
this.currentTime(this.youtube.getCurrentTime());
}
}
}
else {

View File

@ -453,7 +453,16 @@ export class et2_video extends et2_baseWidget implements et2_IDOMNode
if (this.youtube.pauseVideo)
{
this.youtube.pauseVideo();
this.currentTime(this.youtube.getCurrentTime());
if (this.youtube.getCurrentTime() != this._currentTime)
{
// give it a chance to get actual current time ready otherwise we would still get the previous time
// unfortunately we need to rely on a timeout as the youtube seekTo not returning any promise to wait for.
setTimeout(_=>{this.currentTime(this.youtube.getCurrentTime());},500);
}
else
{
this.currentTime(this.youtube.getCurrentTime());
}
}
}
else