fix(notify): sound did not play
cargo devel CI / cargo CI (push) Failing after 1m11s Details

This commit is contained in:
Christoph J. Scherr 2024-07-12 14:06:55 +02:00
parent 5e2621e828
commit bec4f3d68a
2 changed files with 11 additions and 7 deletions

View File

@ -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"

View File

@ -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")]