Level up your Twilio API skills in TwilioQuest, an educational game for Mac, Windows, and Linux. Download Now

メニュー

Expand
Rate this page:

Thanks for rating this page!

We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

オーディオ、ビデオの入出力デバイスの構成

In this guide we’ll show you how to configure audio and video input and output devices in your Twilio Video Rooms application.

Selecting a Specific Video Input

You can use navigator.mediaDevices.enumerateDevices() to select a specific video input like this:

const { connect, createLocalTracks } = require('twilio-video');

navigator.mediaDevices.enumerateDevices().then(devices => {
  const videoInput = devices.find(device => device.kind === 'videoinput');
  return createLocalTracks({ audio: true, video: { deviceId: videoInput.deviceId } });
}).then(localTracks => {
  return connect('my-token', { name: 'my-room-name', tracks: localTracks });
}).then(room => {
  console.log('Connected to room ' + room.name);
});

Audio inputs can also be selected in a similar fashion.

Selecting a Specific Audio Input

Selecting a specific audio input is the same as selecting a specific video input. Just select the audio input device ID and set it on the constraints:

const { connect, createLocalTracks } = require('twilio-video');

navigator.mediaDevices.enumerateDevices().then(devices => {
  const audioInput = devices.find(device => device.kind === 'audioinput');
  return createLocalTracks({ audio: { deviceId: audioInput.deviceId }, video: true });
}).then(localTracks => {
  return connect('my-token', { name: 'my-room-name', tracks: localTracks });
}).then(room => {
  console.log('Connected to room ' + room.name);
}); 

Selecting a Specific Audio Output

You can use navigator.mediaDevices.enumerateDevices() along with HTMLMediaElement.setSinkId() to set the audio output device like this:

const { connect } = require('twilio-video');

let audioOutputDevice;

navigator.mediaDevices.enumerateDevices().then(devices => {
  audioOutputDevice = devices.find(device => device.kind === 'audiooutput');
  return connect('$TOKEN', { name: 'my-room-name' });
}).then(room => {
  room.on('trackAdded', track => {
    if (track.kind === 'audio') {
      const audioElement = track.attach();
      audioElement.setSinkId(audioOutputDevice.deviceId).then(() => {
        document.body.appendChild(audioElement);
      });
    }
  });
});
Rate this page:

ヘルプが必要ですか?

誰しもが一度は考える「コーディングって難しい」。そんな時は、お問い合わせフォームから質問してください。 または、Stack Overflow でTwilioタグのついた情報から欲しいものを探してみましょう。