From 95a466e03a7997ce91b114dc1062e48c5a306756 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 28 Sep 2024 02:44:58 +0200 Subject: [PATCH] use tracing (if enabled) for stream error + sink fmt --- src/sink.rs | 2 +- src/stream.rs | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/sink.rs b/src/sink.rs index 71e278d..148a158 100644 --- a/src/sink.rs +++ b/src/sink.rs @@ -131,7 +131,7 @@ impl Sink { .periodic_access(Duration::from_millis(5), move |src| { if controls.stopped.load(Ordering::SeqCst) { src.stop(); - *controls.position.lock().unwrap() = Duration::ZERO; + *controls.position.lock().unwrap() = Duration::ZERO; } { let mut to_clear = controls.to_clear.lock().unwrap(); diff --git a/src/stream.rs b/src/stream.rs index f81da3d..dd49124 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -195,7 +195,12 @@ impl CpalDeviceExt for cpal::Device { let (mixer_tx, mut mixer_rx) = dynamic_mixer::mixer::(format.channels(), format.sample_rate().0); - let error_callback = |err| eprintln!("an error occurred on output stream: {err}"); + let error_callback = |err| { + #[cfg(feature = "tracing")] + tracing::error!("an error occurred on output stream: {err}"); + #[cfg(not(feature = "tracing"))] + eprintln!("an error occurred on output stream: {err}"); + }; match format.sample_format() { cpal::SampleFormat::F32 => self.build_output_stream::(