{errMsg: "operateGameRecorderVideo:fail GamaRecorder.share:fail no recorded video"}
下面的代码是基于团结引擎开发的。
#region 录制视频
// 开始录制
public void StartRecord()
{
Debug.Log("StartRecord()");
//需要先申请录制权限
GetSettingOption settingOption = new GetSettingOption();
settingOption.fail += (res) => { Debug.LogError(res.errMsg); };
settingOption.success += (res) => {
//用户是否授权了录制
if (res.authSetting.ContainsKey("scope.record") && res.authSetting["scope.record"])
{
Debug.Log("有录制权限");
InternalGameRecord();
}
else
{
Debug.LogError("没有录制权限");
AuthorizeOption authorizeOption = new AuthorizeOption();
authorizeOption.scope = "scope.record";
authorizeOption.fail += (res) => { Debug.LogError(res.errMsg); };
authorizeOption.success += (res) =>
{
Debug.Log("用户同意授权-录制");
InternalGameRecord();
};
Debug.Log("向用户申请录制权限");
WX.Authorize(authorizeOption);
}
};
WX.GetSetting(settingOption);
}
// 开始游戏录制
private void InternalGameRecord()
{
Debug.Log("InternalGameRecord()");
WXGameRecorder recorder = WXBase.GetGameRecorder();
recorder.On("error", (res) => {
Debug.LogFormat("record error: code={0}, message={1}", res.code, res.message);
});
recorder.On("start", (res) => {
Debug.Log("record start");
if (res.code != 0)
{
Debug.LogErrorFormat("start error: code={0}, message={1}", res.code, res.message);
}
});
recorder.On("stop", (res) => {
Debug.Log("record stop");
if (res.code != 0)
{
Debug.LogErrorFormat("stop error: code={0}, message={1}", res.code, res.message);
}
//移除所有监听事件
recorder.Off("error");
recorder.Off("start");
recorder.Off("timeUpdate");
recorder.Off("stop");
});
recorder.On("timeUpdate", (res) => {
Debug.Log("record timeUpdate");
if (res.code != 0)
{
Debug.LogErrorFormat("timeUpdate error: code={0}, message={1}", res.code, res.message);
}
});
GameRecorderStartOption option = new GameRecorderStartOption();
option.bitrate = 600;
option.duration = 10;
option.fps = 24;
option.gop = 2;
option.hookBgm = false;
recorder.Start(option);
}
// 停止录制
public void StopRecord()
{
Debug.Log("StopRecord()");
WXGameRecorder recorder = WXBase.GetGameRecorder();
recorder.Stop();
OperateGameRecorderVideoOption option = new OperateGameRecorderVideoOption();
option.atempo = 1;
option.title = "XXXXXXXXX";
double[][] timeRange = new double[1][];
timeRange[0][0] = 1000;
timeRange[0][1] = 3000;
option.timeRange = timeRange;
//调用此接口报错:
//{errMsg: "operateGameRecorderVideo:fail GamaRecorder.share:fail no recorded video"}
WX.OperateGameRecorderVideo(option);
}
#endregion