

export class RecordManager
{
    private static instance:RecordManager;
    constructor()
    {
        RecordManager.instance = this;
        console.log("new record");
    }
    public static get Instance():RecordManager
    {
        if(RecordManager.instance)
        {
            return RecordManager.instance;
        }
        else
        {
            var curmanager = new RecordManager();
            curmanager.OnNew();
            return curmanager;
        }
    }

    RecordStart()
    {
        if(!Laya.Browser.onMobile)return;
        console.log("RecordStart");
        this.record.start({
            duration: 60,
          })
    }
    RecordStop()
    {
        if(!Laya.Browser.onMobile)return;
        console.log("RecordStop");
        this.record.stop();
    }

    completepath:string;

    ShareVideo(_cb:Function)
    {
        if(!Laya.Browser.onMobile)return;
        Laya.Browser.window.tt.shareAppMessage({
            channel: "video",
            query: "",
            templateId: "266q4fgb8al7i3e7ie", // 替换成通过审核的分享ID
            title: "赢得了我，认你做大哥又如何",
            desc: "赢得了我，认你做大哥又如何",
            extra: {
              videoPath: this.completepath, // 可用录屏得到的本地文件路径
              videoTopics: ["赢得了我，认你做大哥又如何"]
            },
            success() {
                _cb && _cb(true);
              console.log("分享视频成功");
            },
            fail(e) {
                _cb && _cb(false);
              console.log("分享视频失败");
            }
          });
    }

    record:any;
    OnNew()
    {
        if(!Laya.Browser.onMobile)return;
        this.record = Laya.Browser.window.tt.getGameRecorderManager();
        this.record.onStart(res => {
            // 录屏开始
            console.log(res);
          })
        this.record.onStop(res => {
            this.completepath = res.videoPath;
            console.log(res.videoPath);
          })
    }


}