IphoneSE iphone7 plus必现,在回放录制过程中,退出到后台,再进入前台。过一段事件后,微信就会提示,“运行内存不足,请重启小程序”
备注:安卓虽然没有出现内存不足的问题,但是一旦进行前后台切换,之后再stop,onStop回调永远不会再出现。所以安卓也有bug
我的代码如下:
class GameRecordMgr {
constructor() {
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
var recorder = wx.getGameRecorder()
recorder.on('error', (err) => {
console.log("GameRecordMgr recorder err", err)
})
recorder.on('pause', (res) => {
console.log("GameRecordMgr recorder pause", res)
})
recorder.on('start', (res) => {
console.log("GameRecordMgr recorder start", res)
})
recorder.on('resume', (res) => {
console.log("GameRecordMgr recorder resume", res)
})
recorder.on('abort', (res) => {
console.log("GameRecordMgr recorder abort", res)
})
recorder.on('error', (res) => {
console.log("GameRecordMgr recorder error", res)
})
recorder.on('stop', (res) => {
console.log("GameRecordMgr recorder stop", res)
this.m_stopCallBack && this.m_stopCallBack(res.duration)
})
}
}
startGameRecord() {
var bitrate = 1000
if (hf.dataMgr.gameRecordQuality === hf.constants.GAME_RECORD_QUALITY.MID) {
bitrate = 2000
}
else if (hf.dataMgr.gameRecordQuality === hf.constants.GAME_RECORD_QUALITY.HIGH) {
bitrate = 3000
}
var recorder = wx.getGameRecorder()
recorder.start({
fps: 24,
bitrate: bitrate,
hookBgm: false,
duration: 60
})
console.log("xxxxxxxxxx startGameRecord")
}
stopGameRecord(cb) {
var recorder = wx.getGameRecorder()
recorder.stop()
this.m_stopCallBack = cb
}
showShareButton(wxRect, bgm, duration, score) {
var timeRange
if (duration >= 60 * 1000) {
timeRange = [[0, 60 * 1000]]
}
else {
timeRange = [[0, duration]]
}
console.log("showShareButton", wxRect)
if (!this.m_shareBtn) {
var shareBtn = wx.createGameRecorderShareButton({
image: "shareVideo.png",
icon: "",
text: "",
style: {
left: wxRect.left,
top: wxRect.top,
height: wxRect.height,
backgroundColor: "#fff",
iconMarginRight: wxRect.width - 57
},
share: {
query: "type=record",
bgm: bgm,
timeRange: timeRange,
title: {
template: 'default.score',
data: {
score: score
}
},
button: {
template: 'default.challenge'
}
}
})
shareBtn.onTap((info) => {
console.log("xxxxx share Tap ", info)
})
this.m_shareBtn = shareBtn
}
else {
this.m_shareBtn.share = {
query: "type=record",
bgm: bgm,
timeRange: timeRange,
title: {
template: 'default.score',
data: {
score: score
}
},
button: {
template: 'default.challenge'
}
}
}
this.m_shareBtn.show()
}
hideShareBtn() {
if (this.m_shareBtn) {
this.m_shareBtn.hide()
}
}
}
module.exports = GameRecordMgr
后续会进行优化。
我也发现,播放回放后,返回了,但是内存好像还是没有释放,导致游戏卡。