做音视频开发时候,看到阿里音视频能力,有这个功能,怀着好奇的心去搜索果然发现是有办法做到的,可能比较冷门平时用不到,记录下;
javascript
const devices = await navigator.mediaDevices.enumerateDevices();
const audioDevice = devices.find((device) => device.kind === "audiooutput");
const audio = document.createElement("audio");
await audio.setSinkId(audioDevice.deviceId);
console.log(`Audio is being output on ${audio.sinkId}`);