diff examples/menu.rs @ 751:eab7dde1164f

examples: Add music playback to the menu example
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 25 Feb 2020 19:37:19 +0100
parents 31897f650d2d
children a662dddd4a2b
line wrap: on
line diff
--- a/examples/menu.rs
+++ b/examples/menu.rs
@@ -1,3 +1,4 @@
+use ears::{Music, AudioController};
 use luminance::blending::{Equation, Factor};
 use luminance::context::GraphicsContext;
 use luminance::pipeline::{BoundTexture, PipelineState};
@@ -113,6 +114,20 @@ fn main() {
         image
     });
 
+    let music_filename = directory.join("bgm").join("th06_01.wav");
+    let music_filename = music_filename.to_str().expect("non-UTF-8 music filename");
+    let music = match Music::new(music_filename) {
+        Ok(mut music) => {
+            music.set_looping(true);
+            music.play();
+            music
+        }
+        Err(err) => {
+            eprintln!("Impossible to open or play music file: {}", err);
+            return;
+        }
+    };
+
     let mut surface = GlfwSurface::new(WindowDim::Windowed(640, 480), "Touhou", WindowOpt::default()).expect("GLFW window");
 
     let image = jpeg_thread.join().expect("image loading");