-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcaptureStream.html
82 lines (70 loc) · 2.58 KB
/
captureStream.html
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Stream from Offscreen Canvas</title>
<style>
body {
background-color: #333;
color: #fff;
}
div#results {
display: flex;
}
</style>
</head>
<body>
<p>
This example uses the <code>captureStream</code> method to capture the video and audio directly from a <code>video</code> element.
The audio is captured using the Web Audio API and combined with the video stream to create a <code>MediaStream</code>.
</p>
<span>Press start if the video does not play automatically: </span>
<button id="start">Start</button>
<div id="results">
<div>
<h3>Input video</h3>
<video id="source" src="../media/BigBuckBunny_360p30.mp4" controls autoplay playsinline loop></video>
</div>
<div>
<h3>MediaStream output</h3>
<video id="output" controls autoplay playsinline></video>
</div>
</div>
<br>
<button id="hide">Hide source</button>
<button id="mute">Mute local video</button>
<button id="duck">Duck local video</button>
<script>
// Main Thread Script
const startButton = document.querySelector('button#start');
document.addEventListener("DOMContentLoaded", () => {
const sourceVideo = document.getElementById("source");
const outputVideo = document.getElementById("output");
sourceVideo.onplaying = () => {
startButton.disabled = true;
// Combine video stream with audio stream
const videoStream = sourceVideo.captureStream();
outputVideo.srcObject = videoStream;
};
const hideButton = document.querySelector('button#hide');
hideButton.onclick = () => {
sourceVideo.style.visibility = sourceVideo.style.visibility === "hidden" ? "visible" : "hidden"
hideButton.innerText = sourceVideo.hidden ? "Unhide source" : "Hide source";
};
const muteButton = document.querySelector('button#mute');
muteButton.onclick = () => {
sourceVideo.muted = !sourceVideo.muted;
muteButton.innerText = sourceVideo.muted ? "Unmute local video" : "Mute local video";
};
const duckButton = document.querySelector('button#duck');
duckButton.onclick = () => {
sourceVideo.volume = sourceVideo.volume === 0.1 ? 1.0 : 0.1;
duckButton.innerText = sourceVideo.volume === 0.1 ? "Unduck local video" : "Duck local video";
};
startButton.onclick = () => {
sourceVideo.play();
};
});
</script>
</body>
</html>