关于H5页面调取麦克风方法mediaDevices.getUserMedia

想作一个H5页面,在微信端打开,调取手机麦克风进行录音,由于一些缘由 不打算用微信的JSSDK提供的音频接口,因而查到了mediaDevices.getUserMedia()方法,通过测试,说一下兼容性问题ios

 

<audio controls="controls"></audio>
<div class="recorderControl">录制</div>
<script>
    var promise = navigator.mediaDevices.getUserMedia({
        audio: true
     });
     promise.then(function(stream) {
        alert(stream)promise

        recorder.ondataavailable = function() {
          //收集媒体设备 得到到的 能够使用的 媒体流数据
          console.log(event.data)
        }
     });微信

     promise.catch(function(error) {
          alert(error.name)
          alert(error.message)
     });
</script>测试

1.ios手机:spa

    在http环境下,在微信端打开,不弹任何东西;orm

    在https环境下,在微信端打开,不弹任何东西接口

    在http环境下,在safari中打开,走catch方法,分别弹(NotAllowedError)(The request is not allowed by the user agent or the plateform in the current context,possibly because the user denied permission);ip

    在https环境下,在safari中打开,直接弹是否想要访问麦克风,说明调起麦克风成功get

2.安卓手机: io

    在http环境下,在微信端打开,走catch方法,分别弹(NotSupportedError)(only secure origins are allowed(see: https://goo.gl/YOZkNV));

    在https环境下,在微信端打开,直接弹是否想要访问麦克风,说明调起麦克风成功

    在http环境下,在safari中打开,走catch方法,分别弹(PermissionDeniedError)();

    在https环境下,在safari中打开,直接弹是否想要访问麦克风,说明调起麦克风成功

相关文章
相关标签/搜索