audio: add simple playback using rodio
Jason Dagit
6 years ago
16 | 16 | glutin = "*" |
17 | 17 | # panem-nostrum-quotidianum = { path = "../panem-nostrum-quotidianum/" } |
18 | 18 | imagefmt = "*" |
19 | rodio = "0.6.0" |
Binary diff not shown
5 | 5 | } |
6 | 6 | extern crate glutin; |
7 | 7 | extern crate imagefmt; |
8 | extern crate rodio; | |
8 | 9 | |
9 | 10 | pub mod board; |
10 | 11 | pub mod graphics; |
82 | 83 | vbo.bind_uv("uv")?; |
83 | 84 | vbo.unbind(); |
84 | 85 | |
86 | let endpoint = rodio::default_endpoint().unwrap(); | |
87 | ||
88 | let mut audio_queue = rodio::Sink::new(&endpoint); | |
89 | audio_queue.set_volume(0.5); | |
90 | ||
85 | 91 | window.run(|event| { |
86 | 92 | use glutin::{ControlFlow, Event, WindowEvent, VirtualKeyCode}; |
87 | 93 | |
98 | 104 | match k.virtual_keycode { |
99 | 105 | Some(VirtualKeyCode::Q) => |
100 | 106 | return ControlFlow::Break, |
101 |
Some(c) => |
|
107 | Some(c) => { | |
108 | use std::io::BufReader; // Used for audio file reading | |
109 | ||
110 | println!("pressed {:#?}", c); | |
111 | ||
112 | let file = std::fs::File::open("assets/testing.wav").unwrap(); | |
113 | let testing_wav = rodio::Decoder::new(BufReader::new(file)).unwrap(); | |
114 | audio_queue.append(testing_wav); | |
115 | } | |
102 | 116 | _ => (), |
103 | 117 | } |
104 | 118 | } |