Created
May 13, 2021 03:35
-
-
Save matthewjberger/12ce1d5637b2d309df595ecffe35d69f to your computer and use it in GitHub Desktop.
rodio playing an ogg file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
thread::spawn(move || { | |
use ambisonic::rodio::{source::Source, Decoder, OutputStream, Sink}; | |
use std::fs::File; | |
use std::io::BufReader; | |
// Get a output stream handle to the default physical sound device | |
let (_stream, stream_handle) = OutputStream::try_default().unwrap(); | |
// Load a sound from a file, using a path relative to Cargo.toml | |
let file = BufReader::new(File::open("assets/music/theme.ogg").unwrap()); | |
// Decode that sound file into a source | |
let source = Decoder::new(file).unwrap(); | |
let (_stream, stream_handle) = OutputStream::try_default().unwrap(); | |
let sink = Sink::try_new(&stream_handle).unwrap(); | |
// Add a dummy source of the sake of the example. | |
sink.append(source); | |
// The sound plays in a separate thread. This call will block the current thread until the sink | |
// has finished playing all its queued sounds. | |
sink.sleep_until_end(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment