WebRTC GainNode无法在iOS(iPhone)上运行

时间:2018-06-24 10:46:12

标签: javascript webrtc web-audio web-audio-api simplewebrtc

目标

  • 更改实时流的增益(麦克风音量)。
  • 在演示中,您将可以从低增益(0.1)更改为高增益(1)。设置为0.1时,您几乎听不到声音,就像耳语模式一样。

问题

以下代码可在Windows,Android和Safari桌面版本上运行,但是当我尝试在iPhone SE的Safari中运行它时,我没有听到耳语或低增益。我检查了增益节点的值,并在单击按钮时将其设置为0.1,但似乎没有生效。

链接到演示:

https://unrupt.github.io/webrtc-samples/stream-gain-control.html

iPhone上的Safari Media支持的约束

  • aspectRatio
  • deviceId
  • echoCancellation
  • faceingMode
  • frameRate
  • groupId
  • 高度
  • samepleRate
  • sampleSize
  • 音量
  • 宽度

代码:

    <h2 class="w3-center">Media Stream with Gain Control</h2>
    <p class="w3-center">The aim of this sample is to control the gain of the stream</p>
    <audio id="audio" playsinline="true" controls autoplay></audio><br>
    <button class="btn-fn" onclick="start()">Start!</button>
    <button class="btn-fn" onclick="updateGain(0.001)">Low Gain</button>
    <button class="btn-fn" onclick="updateGain(1)">Default Gain</button>
    <script>
        var AudioContext = window.AudioContext || window.webkitAudioContext;

        var localStream;
        var gainNode;
        var ctx;
        var dst;
        var start = () => navigator.mediaDevices.getUserMedia({audio: true})
          .then(stream => audio.srcObject = modifyGain(stream, 2.5))
          .catch(e => log(e));

        var modifyGain = (stream, gainValue) => {
            localStream = stream;
          ctx = new AudioContext();
          var src = ctx.createMediaStreamSource(stream);
          dst = ctx.createMediaStreamDestination();
          gainNode = ctx.createGain();
          gainNode.gain.value = gainValue;
          src.connect(gainNode);
          gainNode.connect(dst);
          outputStream = dst.stream;
          stream.addTrack(outputStream.getAudioTracks()[0]);
          stream.removeTrack(stream.getAudioTracks()[0]);
          //[src, gainNode, dst].reduce((a, b) => a && a.connect(b));
          return stream;
        };

        var updateGain = (value) => {
          gainNode.gain.value = value;
        };

        var log = msg => div.innerHTML += "<br>" + msg;
    </script>

有什么建议可以尝试吗?

0 个答案:

没有答案