forked from ExPixel/miniaudio-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple-enumeration.rs
46 lines (39 loc) · 1.45 KB
/
simple-enumeration.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use miniaudio::{Context, DeviceId, DeviceType, ShareMode};
pub fn main() {
let context = Context::new(&[], None).expect("failed to create context");
context
.with_devices(|playback_devices, capture_devices| {
println!("Playback Devices:");
for (idx, device) in playback_devices.iter().enumerate() {
println!("\t{}: {}", idx, device.name());
print_device_info(&context, DeviceType::Playback, device.id());
}
println!("Capture Devices:");
for (idx, device) in capture_devices.iter().enumerate() {
println!("\t{}: {}", idx, device.name());
print_device_info(&context, DeviceType::Capture, device.id());
}
})
.expect("failed to get devices");
}
pub fn print_device_info(context: &Context, device_type: DeviceType, device_id: &DeviceId) {
// This can fail, so we have to check the result.
let info = match context.get_device_info(device_type, device_id, ShareMode::Shared) {
Ok(info) => info,
Err(err) => {
eprintln!("\t\tfailed to get device info: {}", err);
return;
}
};
println!(
"\t\tSample Rate: {}-{}Hz",
info.min_sample_rate(),
info.max_sample_rate()
);
println!(
"\t\tChannels: {}-{}",
info.min_channels(),
info.max_channels()
);
println!("\t\tFormats: {:?}", info.formats());
}