代码之家  ›  专栏  ›  技术社区  ›  RubbelDieKatz

将默认的“无视频源”/“无视频权限”设置为黑色矩形

  •  0
  • RubbelDieKatz  · 技术社区  · 7 年前

    我用QuaggaJS做条形码扫描器。阿法克嘎嘎创造了一个 video 元素,然后请求摄影机许可。最佳结果是使用 display:none; ,但我想不出任何方法来实现这一点。我需要的元素显示相机饲料一旦扫描仪有它的许可,但在此之前,它应该要么油漆屏幕黑色或被隐藏。

    safari video css issue

    1 回复  |  直到 7 年前
        1
  •  0
  •   RubbelDieKatz    7 年前

    我通过JavaScript隐藏它并在Quagga反馈完成后显示它来修复它。请注意,纯CSS解决方案会更漂亮。

    // Hide the preview before it's fully initialised.
        $('#videoBoundingBox').hide();
        Quagga.init({
            inputStream: {
                name: "Live",
                type: "LiveStream",
                target: document.querySelector('#videoBoundingBox')
            },
            decoder: {
                readers: [
                    "code_128_reader",
                    "ean_reader"
                ]
            }
        }, function (err) {
            if (err) {
                console.log(err);
                setResult(err);
                err = err.toString();
                if (err.search("NotFoundError")) {
                    // No camera found. The user is probably in an office environment.
                    // Redirect to previous orders or show a background image of sorts.
                } else if (err.search("NotAllowedError")) {
                    // The user has blocked the permission request.
                    // We should ask them again just to be sure or redirect them.
                } else {
                    // Some other error.
                }
    
    
                return;
            }
            // Hide the preview before it's fully initialised.
            $('#videoBoundingBox').show();
            setResult("Initialization finished. Ready to start");
            console.log("Initialization finished. Ready to start");
            Quagga.start();
            initializeQuaggaFeedback();
        });