X-Git-Url: https://codewiz.org/gitweb?p=mandelwow.git;a=blobdiff_plain;f=sound.rs;h=d88850b1631d03640fc1d8abd7dc5f73f0ddad06;hp=80afd5cbf37436a5f4090b39eba68c639afe26e3;hb=85f1c7755a86b480276bb3bdd6a47a427f12286d;hpb=af94c9fcbc1e73cc008b090d6355a35eda7aea70 diff --git a/sound.rs b/sound.rs index 80afd5c..d88850b 100644 --- a/sound.rs +++ b/sound.rs @@ -1,5 +1,3 @@ -#[macro_use] - use libxm::XMContext; use sdl2; use sdl2::audio::{AudioCallback, AudioDevice, AudioSpecDesired}; @@ -20,7 +18,7 @@ impl AudioCallback for XmCallback { } pub struct SoundPlayer { - _device: AudioDevice, + _device: Option>, } fn play_xm(raw_xm: &[u8]) -> SoundPlayer { @@ -44,14 +42,21 @@ fn play_xm(raw_xm: &[u8]) -> SoundPlayer { device.resume(); SoundPlayer { - _device: device, + _device: Some(device), } } pub fn start() -> SoundPlayer { - let mut xm = Vec::new(); let filename = "flora.xm"; - File::open(filename).unwrap() - .read_to_end(&mut xm).unwrap(); - return play_xm(&xm); + match File::open(filename) { + Result::Ok(mut f) => { + let mut xm = Vec::new(); + f.read_to_end(&mut xm).unwrap(); + return play_xm(&xm); + }, + Result::Err(err) => { + println!("Couldn't open module {}: {:?}", filename, err); + }, + } + return SoundPlayer { _device: None }; }