|
@@ -56,7 +56,9 @@ module BABYLON {
|
|
private _generateMipMaps: boolean;
|
|
private _generateMipMaps: boolean;
|
|
private _engine: Engine;
|
|
private _engine: Engine;
|
|
private _stillImageCaptured = false;
|
|
private _stillImageCaptured = false;
|
|
- private _poster = false;
|
|
|
|
|
|
+ private _displayingPosterTexture = false;
|
|
|
|
+ private _settings: VideoTextureSettings;
|
|
|
|
+ private _createInternalTextureOnEvent: string;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Creates a video texture.
|
|
* Creates a video texture.
|
|
@@ -93,6 +95,8 @@ module BABYLON {
|
|
|
|
|
|
this.name = name || this._getName(src);
|
|
this.name = name || this._getName(src);
|
|
this.video = this._getVideo(src);
|
|
this.video = this._getVideo(src);
|
|
|
|
+ this._settings = settings;
|
|
|
|
+
|
|
if (settings.poster) {
|
|
if (settings.poster) {
|
|
this.video.poster = settings.poster;
|
|
this.video.poster = settings.poster;
|
|
}
|
|
}
|
|
@@ -106,18 +110,20 @@ module BABYLON {
|
|
|
|
|
|
this.video.setAttribute("playsinline", "");
|
|
this.video.setAttribute("playsinline", "");
|
|
|
|
|
|
- this.video.addEventListener("canplay", this._createInternalTexture);
|
|
|
|
this.video.addEventListener("paused", this._updateInternalTexture);
|
|
this.video.addEventListener("paused", this._updateInternalTexture);
|
|
this.video.addEventListener("seeked", this._updateInternalTexture);
|
|
this.video.addEventListener("seeked", this._updateInternalTexture);
|
|
this.video.addEventListener("emptied", this.reset);
|
|
this.video.addEventListener("emptied", this.reset);
|
|
|
|
+ this._createInternalTextureOnEvent = (settings.poster && !settings.autoPlay) ? "play" : "canplay";
|
|
|
|
+ this.video.addEventListener(this._createInternalTextureOnEvent, this._createInternalTexture);
|
|
|
|
|
|
- if (this.video.readyState >= this.video.HAVE_CURRENT_DATA) {
|
|
|
|
- this._createInternalTexture();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (settings.poster) {
|
|
|
|
|
|
+ const videoHasEnoughData = (this.video.readyState >= this.video.HAVE_CURRENT_DATA);
|
|
|
|
+ if (settings.poster &&
|
|
|
|
+ (!settings.autoPlay || !videoHasEnoughData)) {
|
|
this._texture = this._engine.createTexture(settings.poster!, false, true, scene);
|
|
this._texture = this._engine.createTexture(settings.poster!, false, true, scene);
|
|
- this._poster = true;
|
|
|
|
|
|
+ this._displayingPosterTexture = true;
|
|
|
|
+ }
|
|
|
|
+ else if (videoHasEnoughData) {
|
|
|
|
+ this._createInternalTexture();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -155,9 +161,9 @@ module BABYLON {
|
|
|
|
|
|
private _createInternalTexture = (): void => {
|
|
private _createInternalTexture = (): void => {
|
|
if (this._texture != null) {
|
|
if (this._texture != null) {
|
|
- if (this._poster) {
|
|
|
|
|
|
+ if (this._displayingPosterTexture) {
|
|
this._texture.dispose();
|
|
this._texture.dispose();
|
|
- this._poster = false;
|
|
|
|
|
|
+ this._displayingPosterTexture = false;
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
return;
|
|
return;
|
|
@@ -181,7 +187,7 @@ module BABYLON {
|
|
this._samplingMode
|
|
this._samplingMode
|
|
);
|
|
);
|
|
|
|
|
|
- if (!this.video.autoplay) {
|
|
|
|
|
|
+ if (!this.video.autoplay && !this._settings.poster) {
|
|
let oldHandler = this.video.onplaying;
|
|
let oldHandler = this.video.onplaying;
|
|
let error = false;
|
|
let error = false;
|
|
this.video.onplaying = () => {
|
|
this.video.onplaying = () => {
|
|
@@ -231,7 +237,7 @@ module BABYLON {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- if (!this._poster) {
|
|
|
|
|
|
+ if (!this._displayingPosterTexture) {
|
|
this._texture.dispose();
|
|
this._texture.dispose();
|
|
this._texture = null;
|
|
this._texture = null;
|
|
}
|
|
}
|
|
@@ -278,6 +284,9 @@ module BABYLON {
|
|
if (this.video.readyState < this.video.HAVE_CURRENT_DATA) {
|
|
if (this.video.readyState < this.video.HAVE_CURRENT_DATA) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
+ if (this._displayingPosterTexture) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
|
|
this._engine.updateVideoTexture(this._texture, this.video, this._invertY);
|
|
this._engine.updateVideoTexture(this._texture, this.video, this._invertY);
|
|
}
|
|
}
|
|
@@ -301,7 +310,7 @@ module BABYLON {
|
|
this._onUserActionRequestedObservable = null;
|
|
this._onUserActionRequestedObservable = null;
|
|
}
|
|
}
|
|
|
|
|
|
- this.video.removeEventListener("canplay", this._createInternalTexture);
|
|
|
|
|
|
+ this.video.removeEventListener(this._createInternalTextureOnEvent, this._createInternalTexture);
|
|
this.video.removeEventListener("paused", this._updateInternalTexture);
|
|
this.video.removeEventListener("paused", this._updateInternalTexture);
|
|
this.video.removeEventListener("seeked", this._updateInternalTexture);
|
|
this.video.removeEventListener("seeked", this._updateInternalTexture);
|
|
this.video.removeEventListener("emptied", this.reset);
|
|
this.video.removeEventListener("emptied", this.reset);
|