Device Selection
Kodio allows you to enumerate audio devices and direct recording or playback to specific hardware.
List available devices
Query the system for available audio devices:
// Input devices (microphones)
val inputs = Kodio.listInputDevices()
inputs.forEach { device ->
println("🎤 ${device.name} (${device.id})")
}
// Output devices (speakers, headphones)
val outputs = Kodio.listOutputDevices()
outputs.forEach { device ->
println("🔊 ${device.name} (${device.id})")
}
Each device has:
Record from a specific device
Use an external microphone or other input device:
val inputs = Kodio.listInputDevices()
val externalMic = inputs.find { it.name.contains("USB") }
val recording = Kodio.record(
duration = 5.seconds,
device = externalMic // null uses system default
)
Play to a specific device
Route audio to headphones, speakers, or other output devices:
val outputs = Kodio.listOutputDevices()
val headphones = outputs.find { it.name.contains("Headphones") }
Kodio.play(recording, device = headphones)
In Compose
Pass the device to rememberRecorderState:
@Composable
fun DeviceSelector() {
var selectedDevice by remember { mutableStateOf<AudioDevice?>(null) }
val devices = remember { Kodio.listInputDevices() }
// Device picker
DropdownMenu(/* ... */) {
devices.forEach { device ->
DropdownMenuItem(
text = { Text(device.name) },
onClick = { selectedDevice = device }
)
}
}
// Recorder with selected device
val recorderState = rememberRecorderState(
device = selectedDevice
)
// ...
}
Device selection support varies by platform:
Platform | Support | Notes |
|---|
☕ JVM | ✅ Full | Complete device enumeration |
🍏 macOS | ✅ Full | Complete device enumeration |
🍎 iOS | ✅ Full | AVAudioSession routes |
🤖 Android | ⚠️ Limited | System manages routing; selection available via AudioManager |
🌐 Web | ⚠️ Limited | Browser-dependent; requires getUserMedia with constraints |
Error handling
If a specified device is unavailable:
try {
val recording = Kodio.record(
duration = 5.seconds,
device = specificMic
)
} catch (e: AudioError.DeviceNotFound) {
// Device was disconnected or unavailable
showError("Microphone not found. Using default.")
val recording = Kodio.record(duration = 5.seconds)
}
Last modified: 13 January 2026