Fix youtube video autoplays itself after being seekTo on initiation.

This commit is contained in:
Hadi Nategh 2021-02-26 13:17:44 +01:00
parent f5b1e5a096
commit e5ea49a565
2 changed files with 26 additions and 0 deletions

View File

@ -307,6 +307,19 @@ var et2_video = /** @class */ (function (_super) {
et2_video.prototype.videoLoadnigIsFinished = function () { et2_video.prototype.videoLoadnigIsFinished = function () {
if (this.options.starttime) { if (this.options.starttime) {
this.seek_video(this.options.starttime); this.seek_video(this.options.starttime);
// unfortunately, youtube api autoplays the video after seekTo on initiation
// and there's no way to stop that therefore we need to trick it by manually
// pausing the video (this would bring up the spinner with the black screen,
// in order to avoid that we let the video plays for a second then we pause).
// since the youtube timeline is one second advanced we need to seek back to
// the original stattime although this time because it was manually paused
// we won't have the spinner and black screen instead we get the preview.
if (this._isYoutube())
window.setTimeout(function () {
this.youtube.pauseVideo();
this.youtube.seekTo(this.options.starttime);
;
}.bind(this), 1000);
} }
}; };
et2_video.prototype._onReady = function () { et2_video.prototype._onReady = function () {

View File

@ -443,6 +443,19 @@ export class et2_video extends et2_baseWidget implements et2_IDOMNode
if (this.options.starttime) if (this.options.starttime)
{ {
this.seek_video(this.options.starttime); this.seek_video(this.options.starttime);
// unfortunately, youtube api autoplays the video after seekTo on initiation
// and there's no way to stop that therefore we need to trick it by manually
// pausing the video (this would bring up the spinner with the black screen,
// in order to avoid that we let the video plays for a second then we pause).
// since the youtube timeline is one second advanced we need to seek back to
// the original stattime although this time because it was manually paused
// we won't have the spinner and black screen instead we get the preview.
if (this._isYoutube()) window.setTimeout(function(){
this.youtube.pauseVideo();
this.youtube.seekTo(this.options.starttime);
;}.bind(this), 1000);
} }
} }