From a379b921e711c5679b3010658da30c1bc8b7ef4c 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 --- src/clock.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/clock.rs b/src/clock.rs index 194c30b..947b15f 100644 --- a/src/clock.rs +++ b/src/clock.rs @@ -407,17 +407,19 @@ impl Clock { Self::beep()?; #[cfg(feature = "sound")] { + use rodio::{Decoder, OutputStream, Sink}; 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")); + trace!("bundled sound: {sound:X?}"); // 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 sink = Sink::try_new(&stream_handle).expect("could not create an audio sink"); + sink.append(source); debug!("played bundled sound"); } #[cfg(feature = "desktop")]