forked from sshilko/jQuery-AS3-Webcam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.html
165 lines (146 loc) · 6.05 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
164
165
<!--
/**
* jQuery AS3 Webcam
*
* Copyright (c) 2012, Sergey Shilko ([email protected])
*
* @author Sergey Shilko
* @version 1.1
* @see https://github.com/sshilko/jQuery-AS3-Webcam
*
**/
-->
<html>
<head>
<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="jquery.webcam.as3.js"></script>
<style type="text/css">
.webcam-container {padding:0;margin:0}
.size320x240 { width:320px; height:240px;}
.webcam-container object {border:1px solid #000;}
.webcam-error {color:red;padding-top:10px;}
</style>
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="webcam-container size320x240">
<div id="webcam" class="size320x240"></div>
<div id="webcam-preview" style="display:none;margin-top:-240px;" class="size320x240">
<img src="" alt="Preview" border="0" class="size320x240" />
</div>
</td>
</tr>
<tr>
<td class="webcam-text">
<div><select style="display:none" 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>
</tbody>
</table>
<script type="text/javascript">
$(document).ready(function() {
$("#webcam").webcam({
swffile: "sAS3Cam.swf",
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();
if (cams.length > 1) {
$("#popup-webcam-cams").show();
}
}, 500);
$("#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() {
//$('body').css('cursor', 'wait');
//$(this).hide();
var result = cameraApi.save();
if (result && result.length) {
alert('got base64encoded jpeg with length: ' + result.length);
/* resume camera capture */
cameraApi.setCamera($("#popup-webcam-cams").val());
// $.ajax({'url': "YOUR_URL_HERE",
// 'processData': false,
// 'async': true,
// 'cache': false,
// 'type': 'POST',
// 'dataType': 'json',
// 'contentType': 'text/plain',
// 'data': result,
// 'error': function(xhr, textStatus, error) {
// cameraApi.debug('error', 'Server connection error ("' + textStatus + '"): ' + error);
// alert('some error callback here');
// },
// 'success': function(response) {
// alert('some success callback here');
// //$('#webcam').css('visibility', 'hidden');
// cameraApi.setCamera($("#popup-webcam-cams").val());
// $('body').css('cursor', 'auto');
// }
// });
} else {
cameraApi.debug('error', 'Broken camera');
}
});
var reload = function() {
$('#popup-webcam-take-photo').show();
//$('#webcam-preview').hide();
//$('#webcam').css('visibility', 'visible');
//$('#webcam-preview').find('img').each(function() {
// $(this).attr('src', '');
//});
};
$('#popup-webcam-save').click(function() {
reload();
});
}
});
});
</script>
</body>
</html>