【问题标题】:setSinkId change muliple audio ouputssetSinkId 更改多个音频输出
【发布时间】:2018-06-27 07:57:24
【问题描述】:

问题来了,

首先,我在选择元素中列举了所有可用的设备:

navigator.mediaDevices.enumerateDevices()

当我更改一个输出时,它会在我选择的设备中响起。

HTMLMediaElement.setSinkId(deviceId)

如果我播放另一个音频并更改设备输出 (setSinkId),它也会将第一个设备更改为最后一个设备 ID。所以我在同一个设备中同时拥有这两种声音。

我是否需要最新的 adapter.js 版本才能正确解决该问题?

*********已编辑**********

根据上述评论,它尝试了网络音频,但没有成功。使用 getUserMedia 一切都很好。

navigator.getUserMedia( { audio: true, video: false },
    function (mediaStream) {
        // Create an audio context for the audio
        var ac = new (window.AudioContext || window.webKitAudioContext)();
        // Create a clone of the stream, if not the id of all the stream is default
        //var streamClone = stream.clone();
        var ss = ac.createMediaStreamSource(mediaStream);
        // Create a destination
        var sd = ac.createMediaStreamDestination()
        ss.connect(sd);
        element.srcObject = sd.stream;
        // Play the sound
        element.play();
        element.setSinkId(deviceId).then(function() {
            console.log('Set deviceId('+deviceId+') in the selected audio element');
        });
    },
    function (error) {
        console.log(error);
    }
);

但是使用我的远程流,我听不到任何噪音

var ac = new (window.AudioContext || window.webKitAudioContext)();
// Create a clone of the stream, if not the id of all the stream is default
var streamClone = stream.clone();
var ss = ac.createMediaStreamSource(stream);
// Create a destination
var sd = ac.createMediaStreamDestination()
ss.connect(sd);
// Element is my HTMLMediaElement
element.srcObject = sd.stream;
// Play the sound
element.play();
element.setSinkId(deviceId).then(function() {
   console.log('Set deviceId('+deviceId+') in the selected audio element');
});

【问题讨论】:

    标签: webrtc web-audio-api


    【解决方案1】:

    这很可能是由 Chrome 呈现音频的方式引起的。请参阅 here 以获取描述,该描述还建议使用 webaudio 来解决问题。

    adapter.js 无法解决此问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-19
      • 1970-01-01
      • 1970-01-01
      • 2017-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多