diff options
| author | Teddy Wing | 2018-10-28 17:51:39 +0100 |
|---|---|---|
| committer | Teddy Wing | 2018-10-28 17:58:22 +0100 |
| commit | eb261f29d0ae15c2f941c2d84972bd321bf764ac (patch) | |
| tree | 49b4db718f13d0d901b1485b41329197e80300c4 | |
| parent | 641d94c357b23ad23ad8b67228071a12e619bded (diff) | |
| download | dome-key-map-eb261f29d0ae15c2f941c2d84972bd321bf764ac.tar.bz2 | |
Test of playing an audio file
Success! Using the 'rodio' crate to play an audio file. Include the
audio file in the binary using `include_bytes!`. This makes it so we get
a single self-contained binary.
Struggled a bit with getting the reader/array to `Seek`, but finally
figured out `Cursor` and got it working. Cool.
| -rw-r--r-- | Cargo.toml | 1 | ||||
| -rw-r--r-- | sounds/activ.wav | bin | 0 -> 382190 bytes | |||
| -rw-r--r-- | src/lib.rs | 2 | ||||
| -rw-r--r-- | src/map.rs | 27 | ||||
| -rw-r--r-- | src/sounds.rs | 4 |
5 files changed, 34 insertions, 0 deletions
@@ -14,6 +14,7 @@ libc = "0.2.43" log = "0.4.5" magic-crypt = "2.1.2" quick-error = "1.2.2" +rodio = "0.8.1" serde = "1.0.58" serde_derive = "1.0.58" stderrlog = "0.4.1" diff --git a/sounds/activ.wav b/sounds/activ.wav Binary files differnew file mode 100644 index 0000000..d2a05c9 --- /dev/null +++ b/sounds/activ.wav @@ -19,6 +19,7 @@ extern crate magic_crypt; #[macro_use] extern crate quick_error; +extern crate rodio; #[macro_use] extern crate serde_derive; @@ -36,6 +37,7 @@ mod ffi; mod key_code; mod map; mod parser; +mod sounds; mod trial; use parser::{Action, HeadphoneButton, MapAction, MapGroup, MapKind}; @@ -1,9 +1,13 @@ use std::env; use std::ffi::OsString; +use std::io::BufReader; use std::process::Command; +use rodio::{self, Source}; + use {Action, HeadphoneButton, MapAction, MapKind}; use ffi::State; +use sounds; pub fn run_key_action_for_mode<'a>( state: &mut State, @@ -75,3 +79,26 @@ fn run_action(map_action: &MapAction) { } } +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn play_audio() { + let mode_activated = include_bytes!("../sounds/activ.wav"); + // let mut sound = sounds::MODE_ACTIVATED; + // let mut reader = BufReader::new(sounds::MODE_ACTIVATED); + let file = ::std::fs::File::open("sounds/activ.wav").unwrap(); + // let reader = BufReader::new(&mode_activated[..]); + // let reader = BufReader::new(mode_activated); + // let reader = BufReader::new(file); + let reader = ::std::io::Cursor::new(sounds::MODE_ACTIVATED); +let device = rodio::default_output_device().unwrap(); +// let source = rodio::Decoder::new(reader).unwrap(); +// rodio::play_raw(&device, source.convert_samples()); +// ::std::thread::sleep_ms(2000); +let sink = rodio::play_once(&device, reader).unwrap(); +sink.sleep_until_end(); +sink.play(); + } +} diff --git a/src/sounds.rs b/src/sounds.rs new file mode 100644 index 0000000..8cb6b51 --- /dev/null +++ b/src/sounds.rs @@ -0,0 +1,4 @@ +// const MODE_ACTIVATED = include_bytes!("../sounds/mode_activated.ogg"); +// const MODE_DEACTIVATED = include_bytes!("../sounds/mode_deactivated.ogg"); + +pub const MODE_ACTIVATED: &'static [u8] = include_bytes!("../sounds/activ.wav"); |
