You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

RecordRTCPromisesHandler无法实例化:使用muaz-khan/RecordRTC遇错求助

RecordRTCPromisesHandler实例化报错原因及解决方法

报错原因

你遇到的错误“RecordRTCPromisesHandler: RecordRTCPromisesHandler Interface cannot be instantiated”,核心原因是错误使用new关键字实例化RecordRTCPromisesHandler。

在muaz-khan/RecordRTC库的设计中,RecordRTCPromisesHandler并非可实例化的构造函数,而是一个工厂函数(工具接口),直接调用即可生成录制器实例,不需要用new关键字触发构造。

解决方法

修改代码中创建录制器的逻辑,去掉new关键字:

// 错误写法
let recorder = new RecordRTCPromisesHandler(stream, {
    type: recordingType,
});

// 正确写法
let recorder = RecordRTCPromisesHandler(stream, {
    type: recordingType,
});

另外,也可以直接使用RecordRTC类本身,它已支持Promise风格API,写法更直观:

let recorder = new RecordRTC(stream, {
    type: recordingType,
});

// 异步调用示例
await recorder.startRecording();
const recordedBlob = await recorder.stopRecording();

注意事项

确保调用useRecorderPermission hook时,传入了合法的recordingType值(如'video'、'audio'、'canvas'等),避免因参数非法引发额外异常。

内容的提问来源于stack exchange,提问作者yeln

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 10:40:42