core-egret.Video

egret.Video 使用範例


class Main extends eui.UILayer {

    protected createChildren(): void {
        super.createChildren();
        egret.lifecycle.onPause = () => egret.ticker.pause();
        egret.lifecycle.onResume = () => egret.ticker.resume(); 、
        egret.registerImplementation('eui.IAssetAdapter', new AssetAdapter());
        egret.registerImplementation('eui.IThemeAdapter', new ThemeAdapter());
        this.runGame();
    }

    private async loadResource() {
        let loadingView = this.stage.addChild(new LoadingUI()) as LoadingUI;
        await RES.loadConfig('resource/default.res.json', 'resource/');
        await new Promise(resolve => new eui.Theme('resource/default.thm.json', this.stage).once(eui.UIEvent.COMPLETE, resolve, this));
        await RES.loadGroup('preload', 0, loadingView);
        this.stage.removeChild(loadingView);
    }

    private async runGame() {
        await this.loadResource();
        // --- Edwin 給你最乾淨的程式碼, 從這行以下開始寫喔 ---

        // 取消全屏幕事件 (如果不想全屏幕可以將下面註解拿掉)
        // egret.web['WebVideo']['prototype']['goFullscreen'] = ()=>{};
        // egret.web['WebVideo']['prototype']['exitFullscreen'] = ()=>{};

        // webgl 模式下 video 為 html tag, 並且不是畫在 stage 上
        // 補充:可以自己開發 video 套件讓影片繪製在 canvas 上
        const txt = new eui.Label('click to play!');
        txt.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
            const v = this.addChild(new egret.Video) as egret.Video;
            v.load('https://www.w3schools.com/html/mov_bbb.mp4');
            v.play();
        }, this);
        this.addChild(txt);

    }

}

spacer

沒有留言:

張貼留言