首页新闻找找看学习计划

部署到iis后打不开摄像头

0
悬赏园豆:10 [已关闭问题] 关闭于 2017-07-09 12:44

前端代码:

 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="scanning.aspx.cs" Inherits="GHRK.scanning" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>扫描二维码</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<meta http-equiv="Cache-control" content="no-cache" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />

<script src="Scripts/jquery-1.10.2.min.js"></script>


<style>
* {
margin: 0;
padding: 0;
}

html, body {
height: 100%;
width: 100%;
}

#video {
display: block;
margin: 0 auto;
}

#canvas {
display: block;
}
</style>

<script type="text/javascript">

// Put event listeners into place
window.addEventListener("DOMContentLoaded", function () {
// Grab elements, create settings, etc.
var canvas = document.getElementById("canvas"),
context = canvas.getContext("2d"),
video = document.getElementById("video"),
videoObj = { "video": true },
errBack = function (error) {
console.log("Video capture error: ", error.code);
};
// Put video listeners into place
if (navigator.getUserMedia) { // Standard
navigator.getUserMedia(videoObj, function (stream) {
video.src = stream;
video.play();
}, errBack);
} else if (navigator.webkitGetUserMedia) { // WebKit-prefixed
navigator.webkitGetUserMedia(videoObj, function (stream) {
video.src = window.webkitURL.createObjectURL(stream);
video.play();
}, errBack);
}
else if (navigator.mozGetUserMedia) { // Firefox-prefixed
navigator.mozGetUserMedia(videoObj, function (stream) {
video.src = window.URL.createObjectURL(stream);
video.play();
}, errBack);
}
}, false);

 

// 触发拍照动作
document.getElementById("snap")
.addEventListener("click", function () {
context.drawImage(video, 0, 0, 640, 480);
});

</script>

</head>
<body style="background-color:black">
<form id="form1">

 


<video id="video" autoplay="autoplay"></video>
<div style="color:white;margin:0 auto;text-align:center;width:100%;font-size:30px;font-weight:bold;margin-top:20px;">正在扫描二维码</div>
<script>
window.addEventListener("DOMContentLoaded", function () {
var video = document.getElementById("video"), canvas, context;
try {
canvas = document.createElement("canvas");
context = canvas.getContext("2d");
} catch (e) { alert("not support canvas!"); return; }
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;

if (navigator.getUserMedia)
navigator.getUserMedia(
{ "video": true },
function (stream) {
if (video.mozSrcObject !== undefined) video.mozSrcObject = stream;
else video.src = ((window.URL || window.webkitURL || window.mozURL || window.msURL) && window.URL.createObjectURL(stream)) || stream;
video.play();
},
function (error) {
//if(error.PERMISSION_DENIED)console.log("用户拒绝了浏览器请求媒体的权限",error.code);
//if(error.NOT_SUPPORTED_ERROR)console.log("当前浏览器不支持拍照功能",error.code);
//if(error.MANDATORY_UNSATISFIED_ERROR)console.log("指定的媒体类型未接收到媒体流",error.code);
alert("Video capture error: " + error.code);
}
);
else alert("Native device media streaming (getUserMedia) not supported in this browser");

var doover = 0;
var iCount = setInterval(function () {
if (doover == 0) {
doover = 1
context.drawImage(video, 0, 0, canvas.width = video.videoWidth, canvas.height = video.videoHeight);
$.post('Ewmdo.aspx?flag=' + Math.random(), { "action": "PostEwm", "img": canvas.toDataURL().substr(22) }, function (data, status) {
if (status == "success" && data != "") {

clearInterval(iCount);
window.location.href = data + "&flag=" + Math.random();
}
else {
doover = 0;
}
// alert(data);
}, "text");

}
}, 100);

}, false);
</script>

 

</form>
</body>
</html>

 

 

 

后端代码:

 

public partial class Ewmdo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

if (Request["action"] == "PostEwm")
{

try
{

byte[] imgBytes = Convert.FromBase64String(Request["img"]);
Stream stream = new MemoryStream(imgBytes);
Result result = new ZXing.BarcodeReader().Decode(new Bitmap(stream));
Response.Write(result.Text);
Response.End();
}
catch { Response.Write(""); Response.End(); }
}

}
}

妖狐鬼魅的主页 妖狐鬼魅 | 初学一级 | 园豆:92
提问于:2017-02-19 15:00
< >
分享
所有回答(1)
0

IE要装视频的前端插件的

越天 | 园豆:26 (初学一级) | 2017-05-23 11:24
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册