uniappx中的camera组件,在录像过程中,如果退出了后台,这个时候我仍然需要获取到这段时间录像的信息,我调用停止录像api,但是有时候会无法触发

小黄人波比
- 发布:2025-08-19 16:50
- 更新:2025-08-21 12:20
- 阅读:63
uniappx中的camera组件,在录像过程中,如果退出了后台,有时会无法触发停止录像api
分类:uni-app x
小黄人波比 (作者)
@initdone="handleInitDone">
</camera>
<button @tap="startRecord">录制</button>
<button @tap="stopRecord">停止录制</button>
</view>
</template>
<script lang="uts" setup>
const devicePosition = ref<string>('back'); // 前后摄像头
const flash = ref<string>('off'); // 闪光灯
const frameSize = ref<string>('medium');
function startRecord() {
const context = uni.createCameraContext();
context?.startRecord({
timeout: 60 * 60,
selfieMirror: false,
timeoutCallback: (res : any) => {
console.log("timeoutCallback", res);
},
success: (res : any) => {
console.log("start record success", res);
},
fail: (res : any) => {
console.log("start record fail", res);
}
} as CameraContextStartRecordOptions)
}
function stopRecord() {
const context = uni.createCameraContext();
context?.stopRecord({
compressed: false,
success: (res : CameraContextStopRecordResult) => {
console.log("stop record success", res);
},
fail: (res : any) => {
console.log("stop record fail", res);
}
} as CameraContextStopRecordOptions)
}
function handleStop(e : UniCameraStopEvent) {
console.log("stop", e);
stopRecord();
}
function handleInitDone(e : UniCameraInitDoneEvent) {
console.log("initdone", e.detail);
}
function handleError(e : UniCameraErrorEvent) {
console.log("error", e.detail);
}
onHide(() => {
stopRecord();
})
</script>
<style lang="scss" scoped>
.video_container {
width: 100%;
height: 100%;
}
</style> 操作系统:window11 手机型号华为Mate 50E 操作步骤:点击开始录像,后退出后台,调用stopRecord,有时会无法触发context?.stopRecord,有时候却可以
2025-08-21 15:19
小黄人波比 (作者)
hbuilderx版本:4.75
2025-08-21 15:20