<%@ page language= "C #" autoeventwireup= "true" codebehind= "Pacam.aspx.cs" inherits= "CRM3.cam.pacam"%>
<! DOCTYPE html>
<TITLE>HTML5 Getusermedia demo</title>
<meta name= "viewport" content= "Width=device-width, initial-scale=1.0, maximum-scale=1.0 "/>
<body>
<input type=" button "title=" Turn on camera "value=" Turn on front camera " onclick= "Getmedia (0);"/><input type= "button" title= "Turn on camera" value= "Turn on rear camera" onclick= "Getmedia (1);"/><br />
<video height= "120px" autoplay= "AutoPlay" ></video> <input type= "button" Title= "Take photos" value= "Take photos" onclick= "Getphoto ();"/><br/>
<canvas id= "canvas1" height= "120px" ></ Canvas> <input type= "button" title= "video" value= "video" onclick= "Getvedio ();"/><br/>
<canvas id= "Canvas2" height= "120px" ></CANVAS>
<script type= "Text/javascript";
var Video = Document.queryselector (' video ');
Var audio, audiotype;
var canvas1 = document.getElementById (' canvas1 ');
var context1 = Canvas1.getcontext (' 2d ');
var canvas2 = document.getElementById (' Canvas2 ');
var context2 = Canvas2.getcontext (' 2d ');
Navigator.getusermedia = Navigator.getusermedia | | Navigator.webkitgetusermedia | | Navigator.mozgetusermedia | | Navigator.msgetusermedia;
Window. URL = window. URL | | Window.webkiturl | | Window.mozurl | | Window.msurl;
var exarray = []; Storage device Source ID
Mediastreamtrack.getsources (function (Sourceinfos) {
for (var i = 0; I! = Sourceinfos.length; ++i) {
var sourceinfo = sourceinfos[i];
This will traverse the audio,video, so make a distinction
if (sourceinfo.kind = = = ' Video ') {
Exarray.push (sourceinfo.id);
}
}
});
function Getmedia (a) {
if (Navigator.getusermedia) {
Navigator.getusermedia ({
' Video ': {
' Optional ': [{
' SourceID ': exarray[a]//0 for front camera, 1 for rear
}]
},
' Audio ': true
}, Successfunc, Errorfunc); Success is the callback function that gets the success
}
else {
Alert (' Native device media streaming (Getusermedia) not supported in this browser. ');
}
}
function Successfunc (stream) {
Alert (' Succeed to get media! ');
if (video.mozsrcobject!== undefined) {
In Firefox, Video.mozsrcobject is initially null, not undefined, and we can rely on this to detect Firefox support.
Video.mozsrcobject = stream;
}
else {
video.src = window. URL && window. Url.createobjecturl (stream) | | Stream
}
Video.play ();
Audio
Audio = new audio ();
Audiotype = Getaudiotype (audio);
if (Audiotype) {
AUDIO.SRC = ' Polaroid. ' + Audiotype;
Audio.play ();
}
}
function Errorfunc (e) {
Alert (' error! ' + e);
}
Draws a video frame onto a canvas object, and canvas switches frames every 60ms to create a visual visual effect
function Drawvideoatcanvas (video, context) {
Window.setinterval (function () {
Context.drawimage (video, 0, 0, 90, 120);
}, 60);
}
Get audio format
function Getaudiotype (Element) {
if (Element.canplaytype) {
if (Element.canplaytype (' Audio/mp4; codecs= "mp4a.40.5" ')!== ') {
Return (' AAC ');
} else if (Element.canplaytype (' Audio/ogg; codecs= "Vorbis" ')!== ') {
Return ("Ogg");
}
}
return false;
}
Vedio trigger when playing, draw vedio frame image to Canvas
Video.addeventlistener (' Play ', function () {
Drawvideoatcanvas (video, CONTEXT2);
}, False);
Photo
function Getphoto () {
Context1.drawimage (video, 0, 0, 90, 120); Draws the specified area of the video object to the specified area on the canvas for taking pictures.
}
Video
function Getvedio () {
Drawvideoatcanvas (video, CONTEXT2);
}
</script>
</body>
H5 call the camera before and after the phone, take pictures