Skip to main content

Audio/video - Device Selection

To let the user choose between multiple available input / output devices, you can use the DyteSettingsFragment or DyteSettingsBottomsheet component

val dyteSettingsFragment = DyteSettingsFragment()
dyteSettingsFragment.show(
fragmentManager,
"SOME_TAG_HERE"
)

for video device Selection

You can access list of video devices like meeting.localUser.getVideoDevices() and selected video device can be accessed with meeting.localUser.getSelectedVideoDevice()

To render the video device selection you can use following code

<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/spVideoSource"
android:layout_width="0dp"
android:layout_height="48dp"
android:spinnerMode="dropdown"
/>

and on the kotlin side

val videoDevices = meeting.localUser.getVideoDevices()
val videoAdapter = ArrayAdapter(
requireContext(),
R.layout.dyte_spinner_item,
videoDevices.map { it.type.displayName },
)
videoAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
val selectedVideoDevice = meeting.localUser.getSelectedVideoDevice()
val selectedPosition = videoDevices.indexOfFirst { it.type == selectedVideoDevice?.type }
videoDeviceSpinner.adapter = videoAdapter
videoDeviceSpinner.onItemSelectedListener =
object : OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
val device = videoDevices[position]
meeting.localUser.setVideoDevice(device)
}

override fun onNothingSelected(parent: AdapterView<*>?) {
// no-op
}
}
videoDeviceSpinner.setSelection(selectedPosition, false)

for audio device Selection

You can access list of audio devices like meeting.localUser.getAudioDevices() and selected audio device can be accessed with meeting.localUser.getSelectedAudioDevice()

To render the audio device selection you can use following code

<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/spAudioSource"
android:layout_width="0dp"
android:layout_height="48dp"
android:spinnerMode="dropdown"
/>

and on the kotlin side

val audioDevices = meeting.localUser.getAudioDevices()
val audioAdapter = ArrayAdapter(
requireContext(),
R.layout.dyte_spinner_item,
audioDevices.map { it.type.displayName },
)
audioAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
val selectedAudioDevice = meeting.localUser.getSelectedAudioDevice()
val selectedPosition = audioDevices.indexOfFirst { it.type == selectedAudioDevice?.type }
audioDeviceSpinner.adapter = audioAdapter
audioDeviceSpinner.onItemSelectedListener =
object : OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
val device = audioDevices[position]
meeting.localUser.setAudioDevice(device)
}

override fun onNothingSelected(parent: AdapterView<*>?) {
// no-op
}
}
audioDeviceSpinner.setSelection(selectedPosition, false)