简体   繁体   English

ASP.NET网络摄像头显示

[英]ASP.NET Webcam Display

I'm writing an asp.net site in VB, and am trying to integrate in webcam functionality via javascript. 我正在VB中编写一个asp.net网站,并试图通过javascript集成到网络摄像头功能中。 I'm using webcam.js (found here: https://github.com/jhuckaby/webcamjs ). 我正在使用webcam.js(位于此处: https//github.com/jhuckaby/webcamjs )。 When I created a new project for testing this out and working out the kinks, it worked fine. 当我创建一个新项目来测试并解决问题时,它运行良好。 However, when I attempted to integrate it into my main project, the video does not load and I'm left with a blank screen. 但是,当我尝试将其集成到主项目中时,该视频无法加载,并且屏幕空白。 I can confirm that it does work in the side project in IE, firefox, and chrome, yet works in none of them after integrating it in my main project. 我可以确认它可以在IE,firefox和chrome的辅助项目中正常工作,但是在将其集成到我的主项目中之后却无法在其中任何一个中工作。 The integration process was not complicated, it was mainly just copy and paste and adding the requisite references. 集成过程并不复杂,它主要是复制和粘贴以及添加必要的引用。 I at first was getting problems of it not recognizing 'Webcam' but that went away after I coded in the exact location of the webcam.js file (I understand that this will be a problem later, but I'm more worried about getting it working in debug mode for now so it's fine). 起初,我遇到了无法识别“ Webcam”的问题,但是在我编码了webcam.js文件的确切位置后,问题就消失了(我知道以后会出现问题,但是我更担心得到它现在在调试模式下工作,这样就可以了)。 My code is as follows: 我的代码如下:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebcamPart.aspx.vb" Inherits="IMHmfgb_VerJon.WebCamPart" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager EnablePageMethods="true" runat="server" />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
        <script src="location of webcam.js"></script>
    <div id="my_camera" style="width:640px; height:480px"></div>
    <asp:Label ID="Label1" runat="server" Font-Size="12"></asp:Label>
    <script type="text/javascript">
        function showCam() {
            Webcam.attach('my_camera');
        }
    </script>
    <asp:Button ID="Button2" runat="server" OnClientClick="showCam();return false" Text="Show Cam" /><asp:Button ID="Button1" runat="server" OnClientClick="take_snapshot();return false" Text="Scan" />
    <script type="text/javascript">
        function take_snapshot() {
            Webcam.snap(function (data_uri) {
                PageMethods.BarcodeScan(data_uri, onSuccess, onFailure);
            })
        };
        function onSuccess(result) {
            document.getElementById('<%=Label1.ClientID%>').innerHTML = result;
        };
        function onFailure(result) {
        document.getElementById('<%=Label1.ClientID%>').innerHTML = result;
        };
    </script>
            </ContentTemplate>
            </asp:UpdatePanel>
            <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1" DisplayAfter="500">
        <ProgressTemplate>
            <asp:Image ImageUrl="~\Pictures\Loading.gif" runat="server" ImageAlign="Middle" />
        </ProgressTemplate>
    </asp:UpdateProgress>
    </form>
</body>
</html>

I don't believe that the code above is the problem because, as stated above, it all works fine by itself. 我不认为上面的代码是问题,因为如上所述,它们本身都能正常工作。 This leads me to believe that there is some setting or piece of code somewhere in my main project that is interfering with loading the video, but I have no idea where to look or what to look for. 这使我相信主项目中的某处设置或一段代码会干扰视频的加载,但是我不知道在哪里寻找或寻找什么。

And, after a lot of troubleshooting, I fixed my own problem. 而且,经过大量的故障排除后,我解决了自己的问题。 Apparently it's not enough to simply state the location of the webcam.js file in the following code block: 显然,仅在以下代码块中声明webcam.js文件的位置是不够的:

<script src="location of webcam.js"></script>

You need to have the webcam.js and webcam.swf files located in the same folder as the page that is using them. 您需要将webcam.js和webcam.swf文件放在与使用它们的页面相同的文件夹中。 I found this out by looking at the error console in chrome. 我通过查看chrome中的错误控制台发现了这一点。 I figured the errors would be the same in IE, and as my site is built to run in IE, I checked there first. 我认为错误在IE中将是相同的,并且由于我的站点是为在IE中运行而构建的,因此我首先在此处进行了检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM