From 58077a60f1df8ccea5e1fad0a44c6fbbab946e28 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Mon, 9 May 2022 11:27:59 +0200 Subject: [PATCH] Fix seek to a new time in youtube video does not work when pause action happens instantly after it --- api/js/etemplate/et2_widget_video.js | 10 +++++++++- api/js/etemplate/et2_widget_video.ts | 11 ++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/api/js/etemplate/et2_widget_video.js b/api/js/etemplate/et2_widget_video.js index 6b597a6051..193e6bf47e 100644 --- a/api/js/etemplate/et2_widget_video.js +++ b/api/js/etemplate/et2_widget_video.js @@ -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 { diff --git a/api/js/etemplate/et2_widget_video.ts b/api/js/etemplate/et2_widget_video.ts index aebf65911c..e7bd7ee7e3 100644 --- a/api/js/etemplate/et2_widget_video.ts +++ b/api/js/etemplate/et2_widget_video.ts @@ -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