头条录屏相关功能
//=============================================================================================
//=============================================================================================
//初始化录屏功能
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;
},
//=============================================================================================
//=============================================================================================