From bec4f3d68aa58388a3d8647692477bfdfcfe124b Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Fri, 12 Jul 2024 14:06:55 +0200 Subject: [PATCH] fix(notify): sound did not play --- Cargo.toml | 7 +++++-- src/clock.rs | 11 ++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cac8b7d..ba8a629 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,15 +15,18 @@ categories = ["date-and-time"] [features] default = ["desktop", "sound"] desktop = ["dep:notify-rust"] -sound = ["dep:rodio", "desktop"] +sound = ["dep:awedio", "desktop"] [dependencies] anyhow = "1.0.86" +awedio = { version = "0.4.0", optional = true, default-features = false, features = [ + "cpal", + "rmp3-mp3", +] } chrono = "0.4.38" humantime = "2.1.0" libpt = { version = "0.6.0", features = ["cli"] } notify-rust = { version = "4.11.0", optional = true } ratatui = "0.27.0" -rodio = { version = "0.19.0", optional = true } tui-big-text = "0.4.5" diff --git a/src/clock.rs b/src/clock.rs index 194c30b..ef3eabf 100644 --- a/src/clock.rs +++ b/src/clock.rs @@ -407,17 +407,18 @@ impl Clock { Self::beep()?; #[cfg(feature = "sound")] { + use awedio::Sound; trace!("playing bundled sound"); - use rodio::{source::Source, Decoder, OutputStream}; // only 30 KiB, so let's just include it in the binary and not worry about reading it // from the fs and somehow making the file be there let sound: Cursor<_> = std::io::Cursor::new(include_bytes!("../data/media/alarm.mp3")); - // Get an output stream handle to the default physical sound device - let (_stream, stream_handle) = OutputStream::try_default().unwrap(); - let source = Decoder::new(sound).expect("could not load the included sound"); - stream_handle.play_raw(source.convert_samples())?; // the sound plays in another thread + let (mut manager, _backend) = awedio::start()?; + let decoder = awedio::sounds::decoders::Mp3Decoder::new(sound); + + manager.play(Box::new(decoder.into_memory_sound()?)); + debug!("played bundled sound"); } #[cfg(feature = "desktop")]