-
Notifications
You must be signed in to change notification settings - Fork 14
/
example.html
163 lines (144 loc) · 6.13 KB
/
example.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<!--
/**
* jQuery AS3 Webcam
*
* Copyright (c) 2012, Sergey Shilko (sergey.shilko@gmail.com)
*
* @author Sergey Shilko
* @see https://github.com/sshilko/jQuery-AS3-Webcam
*
**/
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> Example of usage: jQuery AS3 Webcam </title>
<!--<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>-->
<script type="text/javascript" src="http://zeptojs.com/zepto.min.js"></script>
<script type="text/javascript" src="jquery.webcam.as3.js"></script>
<style type="text/css">
.webcam-container {padding:0;margin:0}
.size640x480 { width:640px; height:480px;}
.webcam-container object {border:1px solid #000;}
.webcam-error {color:red;padding-top:10px;}
</style>
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="webcam-container size640x480">
<div id="webcam" class="size640x480"></div>
</td>
</tr>
<tr>
<td class="webcam-text">
<div>
<select id="popup-webcam-cams"></select>
</div>
<div>
<input
id="popup-webcam-take-photo"
type="button"
disabled="disabled"
value="Take a photo"
style="display:none" />
</div>
<p class="webcam-error"></p>
</td>
</tr>
</table>
<br/>
<div id="result"></div>
<br/>
<h4>The result above should look similar to this:</h2>
<img src="the-source.jpeg" align="left" border="1" />
<script type="text/javascript">
$(document).ready(function() {
$("#webcam").webcam({
swffile: "sAS3Cam.swf?v="+Math.random(),
previewWidth: 640,
previewHeight: 480,
resolutionWidth: 640,
resolutionHeight: 480,
/**
* Determine if we need to stretch or scale the captured stream
*
* @see http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Stage.html#scaleMode
* @see http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/StageScaleMode.html
*/
StageScaleMode: 'noScale', //
/**
* Aligns video output on stage
*
* @see http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/StageAlign.html
* @see http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Stage.html#align
* Empty value defaults to "centered" option
*/
StageAlign: 'TL',
noCameraFound: function () {
this.debug('error', 'Web camera is not available');
},
swfApiFail: function(e) {
this.debug('error', 'Internal camera plugin error');
},
cameraDisabled: function () {
this.debug('error', 'Please allow access to your camera');
},
debug: function(type, string) {
if (type == 'error') {
$(".webcam-error").html(string);
} else {
$(".webcam-error").html('');
}
},
cameraEnabled: function () {
this.debug('notice', 'Camera enabled');
var cameraApi = this;
if (cameraApi.isCameraEnabled) {
return;
} else {
cameraApi.isCameraEnabled = true;
}
var cams = cameraApi.getCameraList();
for(var i in cams) {
$("#popup-webcam-cams").append("<option value='"+i+"'>" + cams[i] + "</option>");
}
setTimeout(function() {
$("#popup-webcam-take-photo").removeAttr('disabled');
$("#popup-webcam-take-photo").show();
cameraApi.setCamera('0');
}, 750);
$("#popup-webcam-cams").change(function() {
var success = cameraApi.setCamera($(this).val());
if (!success) {
cameraApi.debug('error', 'Unable to select camera');
} else {
cameraApi.debug('notice', 'Camera changed');
}
});
$('#popup-webcam-take-photo').click(function() {
var result = cameraApi.save();
if (result && result.length) {
var actualShotResolution = cameraApi.getResolution();
var img = new Image();
img.src = 'data:image/jpeg;base64,' + result;
$("#result").append(img);
alert('base64encoded jpeg (' + actualShotResolution[0] + 'x' + actualShotResolution[1] + '): ' + result.length + 'chars');
/* resume camera capture */
cameraApi.setCamera($("#popup-webcam-cams").val());
} else {
cameraApi.debug('error', 'Broken camera');
}
});
var reload = function() {
$('#popup-webcam-take-photo').show();
};
$('#popup-webcam-save').click(function() {
reload();
});
}
});
});
</script>
</body>
</html>