Safari 上音频输出设备数组的长度为 0

Rit*_*ema 3 javascript safari audio-device mediadevices amazon-chime

我正在开发一款利用 Amazon Chime 的视频会议应用程序。我已关注Amazon Chime SDK JS的 npm 页面,并设法获取服务器响应并初始化会议会话。然而,问题是当我尝试获取音频输出设备的数组时,它在 Safari 上是一个长度为零的数组,而在 Chrome 和 Firefox 等浏览器中,它工作得很好,并且我得到了一个非零长度的数组。我该如何解决这个问题?

这是我到目前为止编写的代码:

import {
  ConsoleLogger,
  DefaultDeviceController,
  DefaultMeetingSession,
  LogLevel,
  MeetingSessionConfiguration
} from 'amazon-chime-sdk-js';
 
const logger = new ConsoleLogger('MyLogger', LogLevel.INFO);
const deviceController = new DefaultDeviceController(logger);
 
// You need responses from server-side Chime API. See below for details.
const meetingResponse = /* Server response */;
const attendeeResponse = /* Server response */;
const configuration = new MeetingSessionConfiguration(meetingResponse, attendeeResponse);

const meetingSession = new DefaultMeetingSession(
  configuration,
  logger,
  deviceController
);

const audioInputDevices = await meetingSession.audioVideo.listAudioInputDevices();
const audioOutputDevices = await meetingSession.audioVideo.listAudioOutputDevices();
const videoInputDevices = await meetingSession.audioVideo.listVideoInputDevices();

/* Rest of the code... */
Run Code Online (Sandbox Code Playgroud)

当我在控制台中记录上述数组的长度时,audioOutputDevices数组的长度在 Safari 中为零,而在其他浏览器中则不为零。

Inv*_*vin 5

默认情况下,Firefox 和 Safari 中不启用输出/扬声器设备选择。所以你必须更改默认设置:

以下步骤在 macOS Catalina (v: 10.15.7) 上测试

a) Firefox: 此问题在此讨论:https ://github.com/bigbluebutton/bigbluebutton/issues/12471

  1. 在网址栏中输入about:config
  2. 在搜索栏中搜索属性media.setsinkid.enabled并将其设置为 true
  3. 重新启动浏览器并测试(在浏览器中打开以下链接https://webrtc.github.io/samples/src/content/devices/input-output/)。您现在应该在“音频输出目标”下拉列表中看到值

b) Safari(测试版本:14.1.2):

  1. 确保您在右上角看到“开发”选项卡(如果没有,请启用“ Safari > 首选项 > 高级”,然后选中底部的“在菜单栏中显示开发菜单”)
  2. 导航到“开发>实验功能>允许扬声器设备选择”并确保选中“允许扬声器设备选择”
  3. 重新启动浏览器并在此处进行测试https://webrtc.github.io/samples/src/content/devices/input-output/

如果您想通知用户,则可以使用如下所示的内容(伪代码):

ioDevices = await navigator.mediaDevices.enumerateDevices();
let outputDeviceSelectable = false;
for (let device: ioDevices) {
    if (device.kind == "audiooutput") {
        outputDeviceSelectable = true;
        break;
    }
}
if (outputDeviceSelectable == false) {
    show a pop up to the user to change the default settings
}
Run Code Online (Sandbox Code Playgroud)