zoukankan      html  css  js  c++  java
  • 关于H5页面调取麦克风方法mediaDevices.getUserMedia

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

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

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

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

    1.ios手机:

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

        在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);

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

    2.安卓手机: 

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

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

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

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

  • 相关阅读:
    2.4 自给自足的脚本:位于第一行的#!
    2.3 一个简单的脚本
    2.2 为什么要使用Shell脚本
    JSON 字符串 与 java 对象的转换
    ajax异步提交文件
    jquery选择器
    发现前端框架 bui-min.js
    学习hsf
    Git详解
    java学习材料
  • 原文地址:https://www.cnblogs.com/znLam/p/10139337.html
Copyright © 2011-2022 走看看