作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的用例中,我想记录屏幕事件并将其发送到服务器 [not live]。我为此查看了一些博客/示例演示。但我找不到与此相关的任何内容。我可以找到很多实时流媒体音频/视频,但找不到屏幕录制。
我有以下与此相关的问题,
最佳答案
以下是在 Firefox 中记录屏幕的方法( 更新: 在 this fiddle 中尝试):
var constraints = { video: { mediaSource: "screen", width: 320, height: 200 } };
var start = ms => navigator.mediaDevices.getUserMedia(constraints)
.then(stream => record(stream, ms)
.then(recording => {
stop(stream);
video.src = link.href = URL.createObjectURL(new Blob(recording));
link.download = "recording.blob";
link.innerHTML = "Download blob";
log("Playing "+ recording[0].type +" recording:");
})
.catch(log).then(() => stop(stream)))
.catch(log);
var record = (stream, ms) => {
var rec = new MediaRecorder(stream), data = [];
rec.ondataavailable = e => data.push(e.data);
rec.start();
log(rec.state + " for "+ (ms / 1000) +" seconds...");
var stopped = new Promise((r, e) => (rec.onstop = r, rec.onerror = e));
return Promise.all([stopped, wait(ms).then(() => rec.stop())])
.then(() => data);
};
var stop = stream => stream.getTracks().forEach(track => track.stop());
var wait = ms => new Promise(resolve => setTimeout(resolve, ms));
var log = msg => div.innerHTML += "<br>" + msg;
<button onclick="start(5000)">Record screen!</button>
<div id="div"></div><br>
<video id="video" height="120" width="160" autoplay></video>
<a id="link"></a>
Warning: Sharing your browser window on the web involves security risk! Read about it here!
关于websocket - WebRTC/WebSocket 录屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35857134/
我是一名优秀的程序员,十分优秀!