{"id":28275,"date":"2024-11-24T09:02:42","date_gmt":"2024-11-24T01:02:42","guid":{"rendered":"https:\/\/fwq.ai\/blog\/28275\/"},"modified":"2024-11-24T09:02:42","modified_gmt":"2024-11-24T01:02:42","slug":"web-%e5%89%8d%e7%ab%af%e6%88%aa%e5%9b%be%e6%96%b0%e7%aa%81%e7%a0%b4%ef%bc%9ascreen-capture-api-%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e8%b7%a8%e7%95%8c%e6%88%aa%e5%b1%8f%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/28275\/","title":{"rendered":"Web \u524d\u7aef\u622a\u56fe\u65b0\u7a81\u7834\uff1aScreen Capture API \u5982\u4f55\u5b9e\u73b0\u8de8\u754c\u622a\u5c4f\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173147887154019.jpg\" class=\"aligncenter\" title=\"Web \u524d\u7aef\u622a\u56fe\u65b0\u7a81\u7834\uff1aScreen Capture API \u5982\u4f55\u5b9e\u73b0\u8de8\u754c\u622a\u5c4f\uff1f\u63d2\u56fe\" alt=\"Web \u524d\u7aef\u622a\u56fe\u65b0\u7a81\u7834\uff1aScreen Capture API \u5982\u4f55\u5b9e\u73b0\u8de8\u754c\u622a\u5c4f\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u524d\u7aef\u622a\u56fe\u7684\u8de8\u754c\u7a81\u7834\uff1ascreen capture api<\/strong><\/p>\n<p>\u867d\u7136\u524d\u7aef\u4e2d\u76db\u884c HTML-to-Canvas \u7684\u622a\u56fe\u65b9\u6848\uff0c\u4f46\u5982\u679c\u60a8\u5e0c\u671b\u76f4\u63a5\u622a\u5c4f\uff0c\u65e0\u9700\u5c06 HTML \u8f6c\u6210 Canvas\uff0c\u90a3\u4e48\u4e0d\u59a8\u4e86\u89e3\u4e00\u4e0b Screen Capture API\u3002<\/p>\n<p>\u6b64 API \u5141\u8bb8\u60a8\u6355\u83b7\u5c4f\u5e55\u6d41\uff0c\u4ece\u800c\u5b9e\u73b0\u7c7b\u4f3c\u4e8e Windows \u622a\u56fe\u5de5\u5177\u7684\u622a\u5c4f\u4f53\u9a8c\u3002\u4e0d\u8fc7\uff0c\u4f7f\u7528\u8be5 API \u9700\u8981\u7528\u6237\u7684\u540c\u610f\u3002<\/p>\n<p><strong>\u517c\u5bb9\u6027\uff1a<\/strong><\/p>\n<p>\u4e0d\u5e78\u7684\u662f\uff0cScreen Capture API \u7684\u517c\u5bb9\u6027\u5e76\u4e0d\u7406\u60f3\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li>\u79fb\u52a8\u7aef\u57fa\u672c\u4e0d\u53ef\u7528<\/li>\n<li>PC \u7aef\u4e2d\uff0c\u4ec5 Chrome \u548c Safari \u652f\u6301<\/li>\n<li>Firefox \u4e0d\u652f\u6301<\/li>\n<\/ul>\n<p>\u4ee5\u4e0b\u56fe\u7247\u5c55\u793a\u4e86\u8be5 API \u7684\u517c\u5bb9\u6027\u60c5\u51b5\uff1a<\/p>\n<p>[\u56fe\u7247\u6765\u6e90\uff1a\u8d23\u7f16\u622a\u56fe]<\/p>\n<p><strong>\u4f7f\u7528\u65b9\u6cd5\uff1a<\/strong><\/p>\n<ol>\n<li>\u8bf7\u6c42\u5c4f\u5e55\u6355\u83b7\u6743\u9650<\/li>\n<li>\u521b\u5efa MediaRecorder \u5bf9\u8c61\u5e76\u6355\u83b7\u5c4f\u5e55\u6d41<\/li>\n<li>\u6355\u83b7\u5230\u7684\u5a92\u4f53\u6d41\u53ef\u4ee5\u8f6c\u6362\u4e3a\u56fe\u50cf\u6216\u89c6\u9891<\/li>\n<\/ol>\n<p><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>async function startScreenCapture() {\n  const mediaStream = await navigator.mediaDevices.getDisplayMedia({\n    video: true,\n    audio: false,\n  });\n\n  const mediaRecorder = new MediaRecorder(mediaStream);\n  mediaRecorder.start();\n\n  const chunks = [];\n  mediaRecorder.ondataavailable = (e) =&gt; {\n    chunks.push(e.data);\n  };\n\n  mediaRecorder.onstop = () =&gt; {\n    const videoBlob = new Blob(chunks, { type: \"video\/webm\" });\n    const imageUrl = URL.createObjectURL(videoBlob);\n\n    const img = new Image();\n    img.src = imageUrl;\n    document.body.appendChild(img);\n  };\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fWeb \u524d\u7aef\u622a\u56fe\u65b0\u7a81\u7834\uff1aScreen Capture API \u5982\u4f55\u5b9e\u73b0\u8de8\u754c\u622a\u5c4f\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u7aef\u622a\u56fe\u7684\u8de8\u754c\u7a81\u7834\uff1ascreen capture api \u867d\u7136\u524d\u7aef\u4e2d\u76db\u884c HTML-to-Canvas \u7684\u622a\u56fe\u65b9\u6848\uff0c\u4f46\u5982\u679c\u60a8\u5e0c\u671b\u76f4\u63a5\u622a\u5c4f\uff0c\u65e0\u9700\u5c06 HTML \u8f6c\u6210 Canvas\uff0c\u90a3\u4e48\u4e0d\u59a8\u4e86\u89e3\u4e00\u4e0b Screen Capture API\u3002 \u6b64 API \u5141\u8bb8\u60a8\u6355\u83b7\u5c4f\u5e55\u6d41\uff0c\u4ece\u800c\u5b9e\u73b0\u7c7b\u4f3c\u4e8e Windows \u622a\u56fe\u5de5\u5177\u7684\u622a\u5c4f\u4f53\u9a8c\u3002\u4e0d\u8fc7\uff0c\u4f7f\u7528\u8be5 API \u9700\u8981\u7528\u6237\u7684\u540c\u610f\u3002 \u517c\u5bb9\u6027\uff1a \u4e0d\u5e78\u7684\u662f\uff0cScreen Capture API \u7684\u517c\u5bb9\u6027\u5e76\u4e0d\u7406\u60f3\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u79fb\u52a8\u7aef\u57fa\u672c\u4e0d\u53ef\u7528 PC \u7aef\u4e2d\uff0c\u4ec5 Chrome \u548c Safari \u652f\u6301 Firefox \u4e0d\u652f\u6301 \u4ee5\u4e0b\u56fe\u7247\u5c55\u793a\u4e86\u8be5 API \u7684\u517c\u5bb9\u6027\u60c5\u51b5\uff1a [\u56fe\u7247\u6765\u6e90\uff1a\u8d23\u7f16\u622a\u56fe] \u4f7f\u7528\u65b9\u6cd5\uff1a \u8bf7\u6c42\u5c4f\u5e55\u6355\u83b7\u6743\u9650 \u521b\u5efa MediaRecorder \u5bf9\u8c61\u5e76\u6355\u83b7\u5c4f\u5e55\u6d41 \u6355\u83b7\u5230\u7684\u5a92\u4f53\u6d41\u53ef\u4ee5\u8f6c\u6362\u4e3a\u56fe\u50cf\u6216\u89c6\u9891 \u793a\u4f8b\u4ee3\u7801\uff1a async function startScreenCapture() { const mediaStream = await navigator.mediaDevices.getDisplayMedia({ video: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-28275","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28275","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=28275"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28275\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=28275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=28275"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=28275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}