mirror of
https://github.com/librespot-org/librespot.git
synced 2025-10-03 09:49:31 +02:00
refactor: clean up Rodio fallback handling
This commit is contained in:
parent
648c9e30ea
commit
445f8b10a2
1 changed files with 10 additions and 9 deletions
|
@ -193,11 +193,18 @@ fn create_sink(
|
|||
AudioFormat::S16 => cpal::SampleFormat::I16,
|
||||
};
|
||||
|
||||
let stream = rodio::OutputStreamBuilder::default()
|
||||
.with_device(cpal_device)
|
||||
let stream = match rodio::OutputStreamBuilder::default()
|
||||
.with_device(cpal_device.clone())
|
||||
.with_config(&config.config())
|
||||
.with_sample_format(sample_format)
|
||||
.open_stream_or_fallback()?;
|
||||
.open_stream()
|
||||
{
|
||||
Ok(exact_stream) => exact_stream,
|
||||
Err(e) => {
|
||||
warn!("unable to create Rodio output, falling back to default: {e}");
|
||||
rodio::OutputStreamBuilder::from_device(cpal_device)?.open_stream_or_fallback()?
|
||||
}
|
||||
};
|
||||
|
||||
let sink = rodio::Sink::connect_new(stream.mixer());
|
||||
Ok((sink, stream))
|
||||
|
@ -209,12 +216,6 @@ pub fn open(host: cpal::Host, device: Option<String>, format: AudioFormat) -> Ro
|
|||
host.id().name()
|
||||
);
|
||||
|
||||
let mut format = format;
|
||||
if format != AudioFormat::S16 && format != AudioFormat::F32 {
|
||||
error!("Rodio currently only supports F32 and S16 formats, falling back to S16");
|
||||
format = AudioFormat::S16;
|
||||
}
|
||||
|
||||
let (sink, stream) = create_sink(&host, device, format).unwrap();
|
||||
|
||||
debug!("Rodio sink was created");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue