跳到主要内容

录制

2024年03月12日
柏拉文
越努力,越幸运

一、录制 Canvas


const recordedBlobs = [];
const canvas = document.getElementById('canvas');

function draw(){
……
}

function recorder(){
const canvasStream = canvas.captureStream(30);
const mediaRecorder = new MediaRecorder(canvasStream, {
mimeType: "video/webm",
});
mediaRecorder.ondataavailable = (e) => recordedBlobs.push(e.data);
mediaRecorder.onstop = () => {
const completeBlob = new Blob(recordedBlobs, { type: "video/webm" });
download(completeBlob);
};
}