js 调用摄像头录像
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | <! DOCTYPE html> < html lang="en"> < head > < meta charset="UTF-8"> < meta http-equiv="X-UA-Compatible" content="IE=edge"> < meta name="viewport" content="width=device-width, initial-scale=1.0"> < title >调用摄像头录像</ title > </ head > < body > < video width="640" height="480" id="video" muted autoplay></ video > < button onclick="start()">开始</ button > < button type="button" onclick="stop()">结束</ button > < script > var recoder; var data = [] function start() { navigator.mediaDevices.getUserMedia({ video: true, audio: true }).then(stream => { document.getElementById("video").srcObject = stream; recoder = new MediaRecorder(stream); recoder.ondataavailable = function (e) { data.push(e.data) } recoder.onstop = function () { this.stream.getTracks().forEach(track => track.stop()); var blob = new Blob(data, { type: this.mimeType }); var link = document.createElement("a") link.href = URL.createObjectURL(blob) link.download = new Date().getTime() + ".mp4"; document.body.appendChild(link) link.click() URL.revokeObjectURL(link.href) link.remove() } recoder.start() }) } function stop() { recoder.stop(); data = [] } </ script > </ body > </ html > |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
2020-01-30 css 常用属性
2020-01-30 es6 语法
2020-01-30 vuex 基本语法
2020-01-30 git 常用命令
2020-01-30 css选择器