科尔多瓦浏览器平台相机无法工作

3
我有一个启用了Browser平台的Cordova应用程序。我想在Chrome中使用相机,但调用相机没有任何反馈。它在我的Android设备上表现得很好。
我通过以下命令启动: cordova run browser Chrome按预期打开,并显示完美的控制台日志,告诉我Cordova为相机设置了代理:
 The key "target-densitydpi" is not supported.
 cordova.js:851 adding proxy for Camera
 index.js:47 Received Event: deviceready

我正在使用https://github.com/apache/cordova-plugin-camera/blob/master/doc/index.md中的示例。
在下面的示例中,当我点击链接时,除了日志行“capture”之外什么也不会发生。没有错误,甚至不要求我允许访问我的相机。我已经在HTML5页面上测试了我的相机,并且Chrome可以很好地访问它。
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="msapplication-tap-highlight" content="no" />
        <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <title>Hello World</title>
    </head>
    <body>
        <div class="app">

            <h1>Apache Cordova</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p class="event received">Device is Ready</p>
            </div>
            <img id="myImage"/>
            <a href="javascript: capture()">Camera example</a>
        </div>
        <script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>

    <script>
        function capture()
        {
            console.log("capture")
        navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
            destinationType: Camera.DestinationType.DATA_URL
        });
        }

        function onSuccess(imageData) {
            var image = document.getElementById('myImage');
            image.src = "data:image/jpeg;base64," + imageData;
        }

        function onFail(message) {
            alert('Failed because: ' + message);
        }
    </script>
    </body>
</html>

index.js文件是由Cordova生成的一个文件。

cordova -version => 4.0.0

cordova plugins => org.apache.cordova.camera 0.3.4 "Camera"

如果有人能够指导我完成这个任务,我将非常感激。

提前致谢。

/马丁

1个回答

4
  • 这是Chrome在本地文件网页中的限制,您无法访问相机/麦克风。解决方案是使用本地http服务器,然后从localhost://运行,而不是从file://运行。

  • 无论如何,您最好的解决方案是使用标志启动Chrome: --allow-access-from-files

或者您可以尝试Mozilla,在那里它能正常工作:)

祝好!


太好了。我稍后会尝试一下。谢谢您的回复。 - Martin Verner

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接