通过html显示USB摄像头
点击查看代码
<!DOCTYPE html>
<html lang="zh-CN">
<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">
<script src="adapter.min.js"></script>
<script src="webrtcstreamer.js"></script>
<title>视频播放</title>
</head>
<body>
<div class="show_box">
<h1>实时画面</h1>
<video id="video" autoplay muted></video>
</div>
</body>
<script>
navigator.mediaDevices.getUserMedia({ video: true })
.then(stream => {
const video = document.getElementById('video');
video.srcObject = stream;
video.play();
// WebRTCStreamer.attachMediaStream(video, stream);
})
.catch(error => {
console.error(error);
});
</script>
<style>
body {
margin: 0;
padding: 0;
background-color: #343541;
}
.show_box {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
}
h1 {
color: #fff;
text-align: center;
}
video {
width: 90%;
max-width: 1080px;
}
</style>
</html>
html共享桌面或应用
点击查看代码
<!DOCTYPE html>
<html>
<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">
<script src="adapter.min.js"></script>
<script src="webrtcstreamer.js"></script>
<title>实时显示桌面应用</title>
</head>
<body>
<div id="video-container"></div>
<script src="adapter.min.js"></script>
<script src="webrtcstreamer.js"></script>
<script>
const videoContainer = document.getElementById('video-container');
navigator.mediaDevices.getDisplayMedia({ video: true })
.then(stream => {
const video = document.createElement('video');
video.srcObject = stream;
video.autoplay = true;
video.controls = true;
videoContainer.appendChild(video);
const webrtcstreamer = new WebRtcStreamer();
webrtcstreamer.attachMediaStream(video, stream);
})
.catch(error => {
console.error(error);
});
</script>
</body>
</html>