laya-coreui-es
Version:
laya核心库、ui库es版本,剔除了媒体、TTF等功能。基于 LayaAir-release_2.12.0 修改
76 lines (75 loc) • 2.84 kB
JavaScript
import { BaseTexture } from "./BaseTexture";
import { LayaGL } from "../layagl/LayaGL";
import { WarpMode } from "./WrapMode";
import { FilterMode } from "./FilterMode";
import { WebGLContext } from "../webgl/WebGLContext";
import { Laya } from "../../Laya";
export class VideoTexture extends 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.instance;
super(gl.RGB, false);
this._glTextureType = gl.TEXTURE_2D;
this._width = 1;
this._height = 1;
this._wrapModeU = this._wrapModeV = WarpMode.Clamp;
this._filterMode = 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.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.instance;
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;
}
}
VideoTexture._videoTexturePool = new Array();