Files
JOB/StreamDemo.html
2023-08-01 13:44:46 +02:00

96 lines
2.7 KiB
HTML

<!DOCTYPE html>
<meta charset=utf-8>
<html lang="en">
<head>
<title>GetUserMedia demo</title>
</head>
<body>
<a href="http://eddiela.github.io/JOB" style="position:absolute;left:350px;">Main page</a>
<Canvas id="videoCanvas" width="320" height="240">
</Canvas>
<button id="decode" style="position:absolute;top:225px;left:330px" onclick="Decode()">Start decoding</button>
<button id="stopDecode" style="position:absolute;top:225px;left:450px" onclick="StopDecode()">Stop decoding</button>
<p id="Result" style="position:absolute;top:275px;"></p>
<script src="JOB.js"></script>
<script>
var result = document.getElementById("Result");
JOB.Init();
var localized = [];
var streaming = false;
JOB.StreamCallback = function(result) {
console.log('StreamCallback', result);
if(result.length > 0){
var tempArray = [];
for(var i = 0; i < result.length; i++) {
tempArray.push(result[i].Format+" : "+result[i].Value);
}
Result.innerHTML=tempArray.join("<br />");
}
};
JOB.SetLocalizationCallback(function(result) {
localized = result;
});
JOB.SwitchLocalizationFeedback(true);
c = document.getElementById("videoCanvas");
ctx = c.getContext("2d");
video = document.createElement("video");
video.width = 640;
video.height = 480;
function draw() {
try {
ctx.drawImage(video,0,0,c.width,c.height);
if(localized.length > 0) {
ctx.beginPath();
ctx.lineWIdth = "2";
ctx.strokeStyle="red";
for(var i = 0; i < localized.length; i++) {
ctx.rect(localized[i].x,localized[i].y,localized[i].width,localized[i].height);
}
ctx.stroke();
}
setTimeout(draw,20);
}
catch (e) {
if (e.name == "NS_ERROR_NOT_AVAILABLE") {
setTimeout(draw,20);
} else {
throw e;
}
}
}
navigator.getUserMedia = ( navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia);
if (navigator.getUserMedia) {
navigator.getUserMedia (
{
video: true,
audio: true
},
function(localMediaStream) {
video.src = window.URL.createObjectURL(localMediaStream);
video.play();
draw();
streaming = true;
},
function(err) {
console.log("The following error occured: " + err);
}
);
} else {
console.log("getUserMedia not supported");
}
function Decode() {
if(!streaming) return;
JOB.DecodeStream(video);
}
function StopDecode() {
JOB.StopStreamDecode();
}
</script>
</body>
</html>