头条录屏相关功能

头条录屏相关功能

    //=============================================================================================
    //=============================================================================================

    //初始化录屏功能
    iniTape() {
        //录屏的保存路径
        this.tapePath = null;
        this.tapeStartTime = 0;
        this.tapeMaxTime = 90;
        this.recorder = tt.getGameRecorderManager();
    },
    //手动触发录屏
    onTapeButtonClick() {
        //开始后大于3秒才能关闭
        let nowTime = new Date().getTime();
        let tapeTime = nowTime - this.tapeStartTime;
        if (tapeTime < 3000) {
            cc.log("录屏时间小于3秒");
        } else {
            this.stopTape();
        };
    },
    //录屏时间控制
    tapeTimeControl() {
        let timeCount = 0;
        let callback = function () {
            timeCount++;
            //超过了最大时长或者录制状态为未开启
            if (timeCount >= this.tapeMaxTime) {
                this.unschedule(callback);
                timeCount = 0;
                this.stopTape();
            };
        };
        this.schedule(callback, 1);
    },
    //开始游戏录屏
    startTape() {
        //记录一个时间戳
        this.tapeStartTime = new Date().getTime();
        if (typeof (tt) != "undefined") {
            this.recorder.onStart(res => {
                console.log("录屏开始");
                this.tapeTimeControl();
            });
            this.recorder.start({
                duration: this.tapeMaxTime,
            });
        };
    },
    //结束游戏录屏
    stopTape() {
        if (typeof (tt) != "undefined") {
            this.recorder.onStop(res => {
                console.log(res.videoPath, "录屏结束");
                // do something;
                this.tapePath = res.videoPath;
            });
            this.recorder.stop();

        };
    },

    //录屏分享
    tapeShare() {
        if (typeof (tt) !== "undefined") {
            if (this.game_rules_js.tapePath == null) {
                return;
            };
            //获取分享导语
            tt.shareAppMessage({
                channel: 'video',  //指定为视频分享
                title: '标题',
                extra: {
                    videoPath: this.game_rules_js.tapePath,// 设置视频路径
                    videoTopics: ["话题1", "话题2"]
                },
                success: () => {
                    //分享回调
                    console.log('录屏分享成功');
                    //分享奖励,仅一次
                    this.tapeShareSucces();
                },
                fail: () => {
                    console.log('录屏分享失败', this.tapePath);
                    this.tapeShareFail();
                }
            });
        };
    },
    //录屏分享成功
    tapeShareSucces: function () {
        //do something
    },
    //录屏分享失败
    tapeShareFail: function () {
        //do something;
    },

    //=============================================================================================
    //=============================================================================================

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值