use anyhow::{Result, anyhow}; use cpal::Device; use cpal::traits::HostTrait; use tracing::warn; /// Opens the output with persisted id `id`; an empty id is the system default. A saved /// device that has disappeared falls back to the default instead of failing the join. pub fn open_output(id: &str) -> Result { let host = cpal::default_host(); if !id.is_empty() { let alsa = super::is_alsa(&host); if let Some(device) = super::find_by_id(host.output_devices()?, id, alsa) { return Ok(device); } warn!( device = id, "saved output device not found, using the system default" ); } host.default_output_device() .ok_or_else(|| anyhow!("no default output device")) }