changeset 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 5e5e7136ac92
files Cargo.toml examples/menu.rs
diffstat 2 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/Cargo.toml	Wed Jan 29 18:18:24 2020 +0100
+++ b/Cargo.toml	Tue Feb 25 19:37:19 2020 +0100
@@ -17,3 +17,4 @@
 luminance = "0.38"
 luminance-glfw = { version = "0.12", default-features = false, features = ["log-errors"] }
 luminance-derive = "0.5"
+ears = "0.8"
--- a/examples/menu.rs	Wed Jan 29 18:18:24 2020 +0100
+++ b/examples/menu.rs	Tue Feb 25 19:37:19 2020 +0100
@@ -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 @@
         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");