Record dump files using your mini program
This article describes how to implement recording and forwarding of AR Session dump data in mini programs.
Before you begin
- Understand what AR Session dump files are.
Implementation method
Take using a Switch component as an example to control recording start/stop, and call WeChat's native sharing feature after stopping.
Write WXML interface
Add a Switch form component to the mini program page to control recording start/stop and sharing.
<switch class="switch" checked="{{dumpSessionFlag}}" bindchange="dumpSessionChange">Record data</switch>
Page logic control
In this example, a switch labeled "Record data" appears on the WeChat mini program interface. Its state binds to dumpSessionFlag in the mini program and triggers the callback function dumpSessionChange. Implement in the mini program's ts code:
ar: null,
data: {
//Initial state of form component is off
dumpSessionFlag:false,
},
onReady() {
//Get the xr-frame component in the scene
this.ar = this.selectComponent("#ar-scene");
}
dumpSessionChange(event) {
//Toggle form component display when button is triggered
this.setData({
"dumpSessionFlag":event.detail.value
});
if (this.ar) {
//Call method provided by xr-frame component
this.ar.dumpSession(event.detail.value);
}
},
Implement core recording logic (within 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).
Use wx.showToast() to notify when recording starts. After recording stops, use wx.shareFileMessage() to forward the recorded file via WeChat chat.
/**
* Handles Session recording logic
* @param signal true starts recording, false stops recording and forwards
*/
dumpSession(signal: boolean): void {
// Call interface to get path
const recordPath = session.dumpSession(signal);
// When signal is true, interface returns empty string indicating recording in progress
if (recordPath.length == 0) {
wx.showToast({
title: 'Recording started',
icon: 'success',
duration: 2000
});
return;
}
// When signal is false, process returned file path
wx.shareFileMessage({
filePath: recordPath,
success() {
wx.showToast({
title: 'Recording shared successfully',
icon: 'success',
duration: 2000
});
},
fail() {
wx.showToast({
title: 'Recording share failed',
icon: 'error',
duration: 2000
});
}
})
}
Note
Due to mini program local storage limits (typically 200MB), avoid excessively long recording sessions. Maximum recording duration cannot exceed 10 minutes.