forked from mozilla/webrtc-landing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gum_test_2_camera.html
146 lines (133 loc) · 4.08 KB
/
gum_test_2_camera.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<!DOCTYPE html>
<html>
<head>
<title>gUM Test Page</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" charset="utf-8">
<link href='https://fonts.googleapis.com/css?family=Gentium+Basic:400,700' rel='stylesheet' type='text/css'>
<style>
#main {
display: block;
margin: 0px auto;
text-align: center
}
#content {
display: inline-block;
}
#frames {
display: inline-block;
max-width: 180px;
vertical-align: top;
}
#startbuttons {
display: block;
}
#stopbuttons {
display: none;
}
#message {
font-size: 24px;
font-family: "Gentium Basic", serif;
}
h1 {
font-size: 40px;
font-family: "Gentium Basic", serif;
}
input {
font-size: 28px;
font-family: "Gentium Basic", serif;
}
p {
color: green;
}
p.error {
color: red;
}
</style>
</head>
<body>
<div id="main">
<h2><b>Two-camera getUserMedia Test Page</b></h2>
<a href="http://mozilla.github.com/webrtc-landing">Main webrtc demo page</a><br>
Note: Audio will feedback unless you use a headset!<br><br>
<div id="startbuttons">
<input value="Video Front" onclick="startVideo(true);" type="button">
<input value="Video Rear" onclick="startVideo(false);" type="button">
</div>
<div id="images">
<div id="content"></div>
<div id="frames"></div>
</div>
<div id="message"></div>
<div style="display: block;" id="stopbuttons">
<input value="Stop Front" onclick="stopMedia(true);" type="button">
<input value="Stop Rear" onclick="stopMedia(false);" type="button">
</div>
</div>
<script type="application/javascript">
var video_status = false;
var video = document.createElement("video");
video.setAttribute("width", 160);
video.setAttribute("height", 120);
var video2 = document.createElement("video");
video2.setAttribute("width", 160);
video2.setAttribute("height", 120);
var audio_status = false;
var audio = document.createElement("audio");
audio.setAttribute("controls", true);
var picture_status = false;
var picture = document.createElement("img");
var start = document.getElementById("startbuttons");
var stop = document.getElementById("stopbuttons");
var message = document.getElementById("message");
var content = document.getElementById("content");
var frames = document.getElementById("frames");
var saved_stream = null;
var capturing = false;
function startVideo(front) {
video_status = true;
startMedia(front, {video: true});
// startMedia(front, {video: true /*{ facingMode: direction, require:["facingMode"] } */});
// startMedia(front, front ? { video: true } : { video: true, fake: true});
}
function stopMedia(front) {
if (1 /*video_status*/) {
element = front ? video : video2;
element.mozSrcObject.stop();
element.mozSrcObject = null;
content.removeChild(element);
frames.innerHTML = '';
capturing = false;
//video_status = false;
}
saved_stream = null;
}
function getusermedia_error(err, params) {
if (params.video && params.video.mediaSource) {
message.innerHTML = "<p class='error'>" + err + "</p>" +
"<p>In <a href=\"about:config\">about:config</a>, please enable media.getusermedia.screensharing.enabled<br> and add this" +
" site's domain name to " +
"media.getusermedia.screensharing.allowed_domains in about:config</p>";
} else {
message.innerHTML = "<p class='error'>" + err + "</p>";
}
stopMedia();
}
function startMedia(front, param) {
try {
window.navigator.mozGetUserMedia(param, function(stream) {
message.innerHTML = "<p>Success!</p>";
if (video_status) {
element = front ? video : video2;
content.appendChild(element);
element.mozSrcObject = stream;
element.play();
frames.innerHTML = '';
}
}, function (err) { getusermedia_error(err, param); });
} catch(e) {
getusermedia_error(e, param);
}
}
</script>
</body>
</html>