In-game audio device selection
Allow players to select audio input and output devices.
読み終わるまでの所要時間 1 分最終更新 7ヶ月前
The Vivox SDK automatically uses the system default audio input and output devices. However, you can override this behavior and provide users with a choice of which audio device to use for group voice chat independent of the audio devices that are used for the game.
To perform this override, build a user interface for the game that displays a list of available devices to users that they can select a device from. Build this user interface with the following requests, where audio output devices are called render devices, and audio input devices are called capture devices:
VivoxCoreError IAudioDevices::SetActiveDevice(const FString \&device, const FOnSetActiveDeviceCompletedDelegate \&theDelegate=FOnSetActiveDeviceCompletedDelegate())const TMap<FString, IAudioDevice *> \&IAudioDevices::AvailableDevices()const IAudioDevice IAudioDevices::CommunicationDevice()const IAudioDevice IAudioDevices::SystemDevice()const IAudioDevice IAudioDevices::NullDevice()const IAudioDevice IAudioDevices::ActiveDevice()const IAudioDevice IAudioDevices::EffectiveDevice()
IAudioDevices::AvailableDevicesTMap<FString, IAudioDevice \*>IAudioDeviceIAudioDeviceIAudioDevices::SetActiveDeviceThe following code is an example of how to activate the devices that the user selects:
void UMyClass::SetAudioDevice(const IAudioDevice &inputToSet, const IAudioDevice &outputToSet){ // IClient *VivoxVoiceClient; if (VivoxVoiceClient->AudioInputDevices().ActiveDevice().Id() != inputToSet.Id()) { VivoxVoiceClient->AudioInputDevices().SetActiveDevice(inputToSet); } if (VivoxVoiceClient->AudioOutputDevices().ActiveDevice().Id() != outputToSet.Id()) { VivoxVoiceClient->AudioOutputDevices().SetActiveDevice(outputToSet); }}
When a user selects a new device, the game passes the appropriate in to .
IAudioDeviceIAudioDevices::SetActiveDeviceAlternately, you can pass a virtual device, such as or , in to to set the to the system's default device or the system's communication device, respectively.
IAudioDevices::SystemDevice()IAudioDevices::CommunicationDevice()IAudioDevices::SetActiveDeviceActiveDeviceSet explicitly to prevent input or output.
IAudioDevices::NullDevice()To alert the game to changes in the IAudioDevices setup, bind to the following events:
IAudioDevices::EventAfterDeviceAvailableAddedIAudioDevices::EventBeforeAvailableDeviceRemovedIAudioDevices::EventEffectiveDeviceChanged
Binding to these events helps you to build a responsive system that can handle device hotswapping.