iOS 11 getUserMedia无法正常工作? [英] iOS 11 getUserMedia not working?

查看:337
本文介绍了iOS 11 getUserMedia无法正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apple发布了一条声明,声明 getUserMedia 将在iOS 11上完全运行。安装iOS 11 Beta版本5后,我确实收到一条消息,提示我的网站要求访问我的摄像头和麦克风,但似乎该行:

Apple released a statement that getUserMedia will be fully functional on iOS 11. After installing iOS 11 Beta version 5, I do get a message that my website requests access to my camera and microphone, but it seems that the line:

video.src = window.URL.createObjectURL(stream);

或:

video.srcObject = stream;

不起作用。没有错误,没有例外,只是手机摄像头没有照片。

Does not work. No errors, no exceptions, simply no picture from the phone's camera.

这是我的完整脚本:

$(function () {
     video = document.getElementById('vid');

     navigator.getUserMedia = navigator.getUserMedia ||
                              navigator.webkitGetUserMedia ||
                              navigator.mozGetUserMedia;

     navigator.getUserMedia(
     {
         audio: true,
         video: { facingMode: "user" }
     }, function (stream) {
         video.srcObject = stream;
         //video.src = window.URL.createObjectURL(stream);
     },
     function (err) {           
         alert(err.name);
     });
});

HTML:

<video id="vid" muted autoplay></video>

有人能用吗?任何想法都将不胜感激。

Has anyone got it working? Any ideas would be appreciated.

推荐答案

使用以下解决方案:

$(function () {
    video = document.getElementById('vid');
    video.style.width = document.width + 'px';
    video.style.height = document.height + 'px';
    video.setAttribute('autoplay', '');
    video.setAttribute('muted', '');
    video.setAttribute('playsinline', '');

    var constraints = {
         audio: false,
         video: {
             facingMode: 'user'
         }
    }

    navigator.mediaDevices.getUserMedia(constraints).then(function success(stream) {
        video.srcObject = stream;
    });
});

这篇关于iOS 11 getUserMedia无法正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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