var script = document.createElement('script');
script.src = "flv.min.js";
document.body.appendChild(script);
class Main extends eui.UILayer {
protected createChildren(): void {
super.createChildren();
egret.lifecycle.addLifecycleListener((context) => {
})
egret.lifecycle.onPause = () => {
}
egret.lifecycle.onResume = () => {
}
let assetAdapter = new AssetAdapter();
egret.registerImplementation("eui.IAssetAdapter", assetAdapter);
egret.registerImplementation("eui.IThemeAdapter", new ThemeAdapter());
this.runGame().catch(e => {
console.log(e);
})
}
private async runGame() {
await this.loadResource()
this.createGameScene();
const result = await RES.getResAsync("description_json")
this.startAnimation(result);
await platform.login();
const userInfo = await platform.getUserInfo();
console.log(userInfo);
}
private async loadResource() {
try {
const loadingView = new LoadingUI();
this.stage.addChild(loadingView);
await RES.loadConfig("resource/default.res.json", "resource/");
await this.loadTheme();
await RES.loadGroup("preload", 0, loadingView);
this.stage.removeChild(loadingView);
}
catch (e) {
console.error(e);
}
}
private loadTheme() {
return new Promise((resolve, reject) => {
let theme = new eui.Theme("resource/default.thm.json", this.stage);
theme.addEventListener(eui.UIEvent.COMPLETE, () => {
resolve();
}, this);
})
}
private textfield: egret.TextField;
private _canvasTag;
public bitmap: egret.Bitmap;
public texture = null;
private canvas = null;
private ctx;
private video;
protected createGameScene(): void {
let sky = this.createBitmapByName("bg_jpg");
this.addChild(sky);
var button = new eui.Button();
button.y = 850;
button.label = "播放";
button.horizontalCenter = 0;
button.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onPlay, this);
this.addChild(button);
}
private onPlay() {
if (!this.bitmap) {
this.bitmap = new egret.Bitmap();
this.addChild(this.bitmap);
this.bitmap.x = 80;
this.bitmap.y = 10;
this.addEventListener(egret.Event.ENTER_FRAME, this.loop, this);
this.video = document.createElement("video")
this._canvasTag = flvjs.createPlayer({
type: "flv",
isLive: !0,
hasVideo: !0,
url: "http://.........flv"
});
this._canvasTag.attachMediaElement(this.video);
this._canvasTag.load();
this.video.play();
var canvas = document.createElement('canvas');
canvas.width = 480;
canvas.height = 784;
this.ctx = canvas.getContext('2d');
this.canvas = canvas;
}
}
private updataVideo(x = 0, y = 0, width = 480, height = 784, offsetX = 0, offsetY = 0) {
var x = x;
var y = y;
var width = width;
var height = height;
var offsetX = offsetX;
var offsetY = offsetY;
try {
this.bitmap.width = width;
this.bitmap.height = height;
} catch (error) {
}
if (!this.texture) {
this.texture = new egret.BitmapData(this.canvas) as any;
}
this.texture.$bitmapData = this.texture;
this.texture.$bitmapX = x;
this.texture.$bitmapY = y;
this.texture.$offsetX = offsetX;
this.texture.$offsetY = offsetY;
this.texture.$bitmapWidth = width;
this.texture.$bitmapHeight = height;
this.texture.$getTextureWidth = () => {
return width;
};
this.texture.$getTextureHeight = () => {
return height;
};
this.texture.$sourceWidth = width;
this.texture.$sourceHeight = height;
try {
this.bitmap.texture = this.texture;
} catch (error) {
}
}
private loop() {
this.updataVideo(0, 0, 480, 784, 0, 0);
this.ctx.drawImage(this.video, 0, 0, 480, 784);
}
private createBitmapByName(name: string): egret.Bitmap {
let result = new egret.Bitmap();
let texture: egret.Texture = RES.getRes(name);
result.texture = texture;
return result;
}
private startAnimation(result: Array<any>): void {
let parser = new egret.HtmlTextParser();
}
private onButtonClick(e: egret.TouchEvent) {
let panel = new eui.Panel();
panel.title = "Title";
panel.horizontalCenter = 0;
panel.verticalCenter = 0;
this.addChild(panel);
}
}
declare class flvjs {
public constructor();
play();
static isSupported();
static createPlayer(a:any);
}