UNPKG

laya-coreui-es

Version:

laya核心库、ui库es版本,剔除了媒体、TTF等功能。基于 LayaAir-release_2.12.0 修改

80 lines (79 loc) 3.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.VideoTexture = void 0; const BaseTexture_1 = require("./BaseTexture"); const LayaGL_1 = require("../layagl/LayaGL"); const WrapMode_1 = require("./WrapMode"); const FilterMode_1 = require("./FilterMode"); const WebGLContext_1 = require("../webgl/WebGLContext"); const Laya_1 = require("../../Laya"); class VideoTexture extends BaseTexture_1.BaseTexture { static _update() { var pool = VideoTexture._videoTexturePool; for (var i = 0, n = pool.length; i < n; i++) { var videoElement = pool[i]; (videoElement) && videoElement._updateVideoData(); } } constructor() { var gl = LayaGL_1.LayaGL.instance; super(gl.RGB, false); this._glTextureType = gl.TEXTURE_2D; this._width = 1; this._height = 1; this._wrapModeU = this._wrapModeV = WrapMode_1.WarpMode.Clamp; this._filterMode = FilterMode_1.FilterMode.Bilinear; this._setWarpMode(gl.TEXTURE_WRAP_S, this._wrapModeU); this._setWarpMode(gl.TEXTURE_WRAP_T, this._wrapModeV); this._setFilterMode(this._filterMode); this._needUpdate = false; this._readyed = true; VideoTexture._videoTexturePool.push(this); } get video() { return this._video; } set video(value) { if (!value || !(value instanceof HTMLVideoElement)) return; this._video = value; if (Laya_1.Laya.Browser.onMobile) { this._video["x5-playsInline"] = true; this._video["x5-playsinline"] = true; this._video.x5PlaysInline = true; this._video.playsInline = true; this._video["webkit-playsInline"] = true; this._video["webkit-playsinline"] = true; this._video.webkitPlaysInline = true; this._video.playsinline = true; this._video.style.playsInline = true; this._video.crossOrigin = "anonymous"; this._video.setAttribute('crossorigin', "anonymous"); this._video.setAttribute('playsinline', 'true'); this._video.setAttribute('x5-playsinline', 'true'); this._video.setAttribute('webkit-playsinline', 'true'); this._video.autoplay = true; } } _updateVideoData() { if (!this._video || !this._needUpdate) return; var gl = LayaGL_1.LayaGL.instance; WebGLContext_1.WebGLContext.bindTexture(gl, this._glTextureType, this._glTexture); gl.texImage2D(this._glTextureType, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, this._video); } videoPlay() { this._video.play(); this._needUpdate = true; } videoPause() { this._video.pause(); this._needUpdate = false; } destroy() { super.destroy(); this._video = null; } } exports.VideoTexture = VideoTexture; VideoTexture._videoTexturePool = new Array();