Use your mini program to record dump files
This article describes how to implement recording and forwarding of AR Session dump data in a mini program.
Before you start
- Learn what an AR Session dump file is.
Implementation method
Use a Switch component as an example to control the start and end of recording, and call the native WeChat sharing feature after recording ends.
Write WXML interface
Add a form component Switch to the mini program page to control starting recording, ending recording, and forwarding the record.
<switch class="switch" checked="{{dumpSessionFlag}}" bindchange="dumpSessionChange">记录数据</switch>
Page logic control
In this example, a switch named "Record data" appears on the WeChat Mini Program interface. Its state is bound to dumpSessionFlag in the mini program, and it is bound to the callback function dumpSessionChange in the mini program. Implement the following in the mini program ts code:
ar: null,
data: {
//表单组件的初始状态为 关闭
dumpSessionFlag:false,
},
onReady() {
//获取场景中的 xr-frame 组件
this.ar = this.selectComponent("#ar-scene");
}
dumpSessionChange(event) {
//按钮触发时切换表单组件的显示
this.setData({
"dumpSessionFlag":event.detail.value
});
if (this.ar) {
//调用 xr-frame 组件提供的方法
this.ar.dumpSession(event.detail.value);
}
},
Implement core recording logic (inside xr-frame component)
Control the recording process by calling the session.dumpSession(signal: boolean) interface:
- Pass
true: start recording. - Pass
false: stop recording and return the generated temporary file path (tempFilePath).
When recording starts, you can prompt that recording has started through wx.showToast(). When recording ends, use wx.shareFileMessage() to forward the recorded file through WeChat chat.
/**
* 处理 Session 记录逻辑
* @param signal true 为开始记录,false 为结束记录并转发
*/
dumpSession(signal: boolean): void {
// 调用接口获取路径
const recordPath = session.dumpSession(signal);
// signal 为 true 时,接口返回空字符串,表示正在记录
if (recordPath.length == 0) {
wx.showToast({
title: '开始记录数据',
icon: 'success',
duration: 2000
});
return;
}
// signal 为 false 时,处理返回的文件路径
wx.shareFileMessage({
filePath: recordPath,
success() {
wx.showToast({
title: '记录转发成功',
icon: 'success',
duration: 2000
});
},
fail() {
wx.showToast({
title: '记录转发失败',
icon: 'error',
duration: 2000
});
}
})
}
Note
Due to the local storage limit of mini programs, usually 200 MB, it is recommended that a single recording should not be too long, and the maximum recording duration must not exceed 10 minutes.