【问题标题】:Primefaces 6.2 PhotoCam - Webcam Errors with Firefox / SafariPrimefaces 6.2 PhotoCam - Firefox / Safari 的网络摄像头错误
【发布时间】:2018-10-11 12:03:56
【问题描述】:

我正在尝试使用 Primeface 的 PhotoCam(版本 6.2),并且使用他们展示的示例,相机在 Firefox(开发者版 63.0b13)或 Safari 版本 12 上不适合我......并且不工作在移动设备上的 Safari 上(移动设备在 iOS12 上)。

它使用 https 部署到一个站点,并且可以在桌面和移动浏览器的 Chrome 中运行。

我目前正在使用展示演示,在此处找到(代码也在下面发布):

https://www.primefaces.org/showcase/ui/multimedia/photoCam.xhtml

我什至下载了展示战争文件并尝试了该版本,但没有成功。

有人可以帮忙吗?

发生了什么事?

在 Firefox 上:

  • 我得到允许摄像头访问的提示,我点击确定。
  • 我收到运行 Adob​​e Flash 的提示,我同意。
  • 接受两者后,相机“盒子”只是白色的。
  • 当我单击捕获时,我收到的错误是“Webcam.js 错误:尚未加载网络摄像头”。
  • 注意:控制台在页面加载时返回“return statement [Learn More] 后无法访问代码”,但没有其他消息 接受两个提示后出现。

在 Safari 上:

  • 我得到允许摄像头访问的提示,我点击确定。
  • 我收到错误“Webcam.js 错误:无法访问网络摄像头:TypeError:类型错误 TypeError:类型错误”

在移动设备上的 Safari 上:

  • 我收到错误“Webcam.js 错误:无法访问网络摄像头:错误: 无效约束错误:无效约束”

这里是 xhtml:

<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
            xmlns:p="http://primefaces.org/ui" template="/common/template.xhtml">
<ui:define name="title">PhotoCam</ui:define>
<ui:define name="content">
    <h:form>
        <h:panelGrid columns="3" cellpadding="5">
            <p:photoCam widgetVar="pc" listener="#{photoCamView.oncapture}" update="photo"/>
            <p:commandButton type="button" value="Capture" onclick="PF('pc').capture()"/>
            <p:outputPanel id="photo">
                <p:graphicImage name="demo/images/photocam/#{photoCamView.filename}.jpeg"
                                rendered="#{not empty photoCamView.filename}"/>
            </p:outputPanel>
        </h:panelGrid>
    </h:form>
</ui:define>

这里是java类

public class PhotoCamView {

private String filename;

private String getRandomImageName() {
    int i = (int) (Math.random() * 10000000);

    return String.valueOf(i);
}

public String getFilename() {
    return filename;
}

public void oncapture(CaptureEvent captureEvent) {
    filename = getRandomImageName();
    byte[] data = captureEvent.getData();

    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
    String newFileName = externalContext.getRealPath("") + File.separator + "resources" + File.separator + "demo" +
                                File.separator + "images" + File.separator + "photocam" + File.separator + filename + ".jpeg";

    FileImageOutputStream imageOutput;
    try {
        imageOutput = new FileImageOutputStream(new File(newFileName));
        imageOutput.write(data, 0, data.length);
        imageOutput.close();
    }
    catch(IOException e) {
        throw new FacesException("Error in writing captured image.", e);
    }
}}

感谢您对此提供的任何帮助。

(我也在 Primefaces 论坛上发布了这个,希望这里或那里有人可以帮助我。当我弄清楚这两个网站时,我会更新)

克里斯蒂娜

【问题讨论】:

    标签: java jsf primefaces


    【解决方案1】:

    只需从Github 下载 webcam.js 并将其放在您的 xhtml 文件夹中。 然后将&lt;script type="text/javascript" src="webcam.js"&gt;&lt;/script&gt; 添加到您的 xhtml 文件中

    【讨论】:

      【解决方案2】:

      我最近刚刚将 Photocam 更新到其 JS 插件的最新版本,并且还修复了 IE11 的类似错误。见这里:

      https://github.com/primefaces/primefaces/issues/4094

      https://github.com/primefaces/primefaces/issues/3755

      我强烈建议尝试 GitHub 上的 PrimeFaces 6.3-SNAPSHOT 版本,并让我们知道这个最新版本是否解决了您的问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-10-28
        • 1970-01-01
        • 1970-01-01
        • 2020-08-13
        • 2012-10-11
        • 1970-01-01
        • 1970-01-01
        • 2018-03-18
        相关资源
        最近更新 更多