如何解决iOS 11 Safari getUserMedia“无效约束”问题 [英] How to resolve iOS 11 Safari getUserMedia "Invalid constraint" issue

查看:523
本文介绍了如何解决iOS 11 Safari getUserMedia“无效约束”问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在iOS 11中的Safari中运行以下代码。它应该提示用户访问其设备相机,然后将其显示在我的< video autoplay id =video中>< / video> 元素。但是,在iOS 11中运行时,会导致抛出 OverconstrainedError

I'm attempting to run the following code in Safari in iOS 11. It should prompt the user to give access to their devices camera and then display it in my <video autoplay id="video"></video> element. However, when running in iOS 11, it results in an OverconstrainedError to be thrown:

{message: "Invalid constraint", constraint: ""}




  • 代码在Android中正常运行并成功打开相机。

  • 我尝试了多个有效配置而没有运气。

  • 我知道iOS 11刚出来所以它可能是一个bug,但是有什么想法吗?有没有其他人遇到这个?

    I know iOS 11 just came out so it may be a bug, but any thoughts? Has anyone else run into this?

    代码:

    var video = document.getElementById('video');
    if(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
         navigator.mediaDevices.getUserMedia({video: true})
             .then(function(stream) {
                 video.src = window.URL.createObjectURL(stream);
                 video.play();
             })
             .catch(function(err) {
                 console.log(err);
             });
    }
    






    编辑1



    我运行 navigator.mediaDevices.getSupportedConstraints()并返回以下内容:

    {
        aspectRatio: true,
        deviceid: true,
        echoCancellation: false,
        facingMode: true,
        frameRate: true,
        groupId: true,
        height: true,
        sampleRate: false,
        sampleSize: false,
        volume: true,
        width: true
    }
    

    我试过配置省略视频属性,但没有运气。

    I've tried configurations omitting the video property, but had no luck.

    推荐答案

    它似乎是一个被纠正的错误,因为我只是再次尝试并且错误消息不再出现。

    It appears to have been a bug that was corrected, because I just tried it again and the error message no longer appears.

    请注意,虽然错误消息消失了,但我做了必须再做一次更改才能正常工作,这是在 t中添加 video.srcObject = stream; 母鸡回调。

    Note that while the error message went away, I did have to make one more change for it to work, which was adding video.srcObject = stream; in the then callback.

    这篇关于如何解决iOS 11 Safari getUserMedia“无效约束”问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆