How to select audioOutput with OpenTok

前端 未结 2 1292
滥情空心
滥情空心 2021-01-07 03:02

I am building a simple WebRTC app with OpenTok. I need to be able to select camera, audio input and audio output. Currently that doesn\'t s

2条回答
  •  再見小時候
    2021-01-07 03:50

    So, The answer gave by @Adam Ullman is not valid anymore since there is a separate audio element created alongside the video element preventing us to use the setSinkId method of the video element.

    I found a solution consisting in finding the audio element from the video one and using its own setSinkId. Code:

      const subscriber_videoElementCreated = async event => {
        const videoElem = event.element;
        const audioElem = Array.from(videoElem.parentNode.childNodes).find(child => child.tagName === 'AUDIO');
        if (typeof audioElem.sinkId !== 'undefined') {
          try {
            await audioElem.setSinkId(deviceId);
          } catch (err) {
            console.log('Could not update speaker ', err);
          }
        }
      };
    

提交回复
热议问题