babylon.videoTexture.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. var __extends = this.__extends || function (d, b) {
  2. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  3. function __() { this.constructor = d; }
  4. __.prototype = b.prototype;
  5. d.prototype = new __();
  6. };
  7. var BABYLON;
  8. (function (BABYLON) {
  9. var VideoTexture = (function (_super) {
  10. __extends(VideoTexture, _super);
  11. function VideoTexture(name, urls, size, scene, generateMipMaps, invertY) {
  12. var _this = this;
  13. _super.call(this, null, scene, !generateMipMaps, invertY);
  14. this._autoLaunch = true;
  15. this.name = name;
  16. this.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
  17. this.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
  18. this._texture = scene.getEngine().createDynamicTexture(size, size, generateMipMaps);
  19. var textureSize = this.getSize();
  20. this.video = document.createElement("video");
  21. this.video.width = textureSize.width;
  22. this.video.height = textureSize.height;
  23. this.video.autoplay = false;
  24. this.video.loop = true;
  25. this.video.addEventListener("canplaythrough", function () {
  26. if (_this._texture) {
  27. _this._texture.isReady = true;
  28. }
  29. });
  30. urls.forEach(function (url) {
  31. var source = document.createElement("source");
  32. source.src = url;
  33. _this.video.appendChild(source);
  34. });
  35. this._lastUpdate = new Date().getTime();
  36. }
  37. VideoTexture.prototype.update = function () {
  38. if (this._autoLaunch) {
  39. this._autoLaunch = false;
  40. this.video.play();
  41. }
  42. var now = new Date().getTime();
  43. if (now - this._lastUpdate < 15) {
  44. return false;
  45. }
  46. this._lastUpdate = now;
  47. this.getScene().getEngine().updateVideoTexture(this._texture, this.video, this._invertY);
  48. return true;
  49. };
  50. return VideoTexture;
  51. })(BABYLON.Texture);
  52. BABYLON.VideoTexture = VideoTexture;
  53. })(BABYLON || (BABYLON = {}));
  54. //# sourceMappingURL=babylon.videoTexture.js.map