Add device validation before using saved audio device

- Validate device has supported output configs before using
- Fall back to default if saved device is invalid
- Reduces polling frequency to 10 seconds
This commit is contained in:
vicrodh committed 2026-01-11 11:10:02 -06:00
1 parent f6b2b07f5d
commit 3fd3d25bdc
2 files changed
+25 -6

No files matched your search

+23 -4
View File
@@ -190,18 +190,37 @@ impl Player {
// Get the audio host // Get the audio host
let host = rodio::cpal::default_host(); let host = rodio::cpal::default_host();
// Helper to validate a device has supported output configs
let is_device_valid = |d: &rodio::cpal::Device| -> bool {
d.supported_output_configs()
.map(|configs| configs.count() > 0)
.unwrap_or(false)
};
// Find the requested device or use default // Find the requested device or use default
let device = if let Some(ref name) = device_name { let device = if let Some(ref name) = device_name {
log::info!("Looking for audio device: {}", name); log::info!("Looking for audio device: {}", name);
host.output_devices() let found = host.output_devices()
.ok() .ok()
.and_then(|mut devices| { .and_then(|mut devices| {
devices.find(|d| d.name().ok().as_ref() == Some(name)) devices.find(|d| d.name().ok().as_ref() == Some(name))
}) });
.or_else(|| {
// Validate the found device
match found {
Some(d) if is_device_valid(&d) => {
log::info!("Found and validated device: {}", name);
Some(d)
}
Some(_) => {
log::warn!("Device '{}' found but has no valid output configs, using default", name);
host.default_output_device()
}
None => {
log::warn!("Device '{}' not found, using default", name); log::warn!("Device '{}' not found, using default", name);
host.default_output_device() host.default_output_device()
}) }
}
} else { } else {
log::info!("Using default audio device"); log::info!("Using default audio device");
host.default_output_device() host.default_output_device()
+2 -2
View File
@@ -61,8 +61,8 @@
onMount(() => { onMount(() => {
loadStatus(); loadStatus();
// Poll for updates while playing // Poll less frequently - only needed to detect settings changes
const interval = setInterval(loadStatus, 5000); const interval = setInterval(loadStatus, 10000);
return () => clearInterval(interval); return () => clearInterval(interval);
}); });
</script> </script>