如何阻止 iOS 设备在授予麦克风访问权限后降低音量?

问题描述 投票:0回答:0

我发现这个问题已经被问过几次了,但不是最近才被问到,而且没有任何有用的答案。

我的网络应用程序允许用户授予麦克风权限:


// Check if the browser supports the getUserMedia method
    if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
      // Request microphone access
      navigator.mediaDevices.getUserMedia({ audio: true })
        .then(function(audioStream) {
          // Microphone access granted, do something with the stream
          console.log("Microphone access granted");

并在音频准备好时收听响应:


// Add an event listener for the custom event
document.addEventListener("audioReady", function() {
  audioElement.play()
    .then(() => console.log("Playback started"))
    .catch(e => console.log("Playback failed due to: ", e));
});


在 Android 和 Windows 设备上,音频会以正确的音量播放,但在 iOS 设备上,音量会在用户授予麦克风权限后降低。

我的理解是苹果故意将其内置到操作系统中,以便用户在对着麦克风说话时能够听到自己的声音。对于我的应用程序,当播放音频时麦克风将始终关闭。

我想知道是否有人找到了一种方法来确保麦克风关闭时音量保持不变(但已获得许可)。这似乎在具有音频会话 API 的本机 iOS 应用程序中是可能的,但我想知道是否有人有网络应用程序的解决方法?

感谢您的帮助。

我尝试使用音频会话 API 将会话设置为 .playAndRecord,但知道它可能无法在浏览器中工作。

ios audio volume microphone
© www.soinside.com 2019 - 2024. All rights reserved.