Skip to content

Instantly share code, notes, and snippets.

@matthewjberger
Created May 13, 2021 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewjberger/12ce1d5637b2d309df595ecffe35d69f to your computer and use it in GitHub Desktop.
Save matthewjberger/12ce1d5637b2d309df595ecffe35d69f to your computer and use it in GitHub Desktop.
rodio playing an ogg file
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