Created
January 10, 2018 01:17
-
-
Save anonymous/b92600c200de921ed5cf393aff8daf68 to your computer and use it in GitHub Desktop.
Rust code shared from the playground
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
extern crate rodio; | |
use std::io::BufReader; | |
use std::io::Read; | |
fn main() { | |
let endpoint = rodio::default_endpoint().unwrap(); | |
let sink = rodio::Sink::new(&endpoint); | |
let sample_b =load_samplesbuffer("examples/music.ogg"); | |
sink.append(sample_b); | |
sink.sleep_until_end(); | |
} | |
pub fn load_samplesbuffer(filename: &str) -> rodio::buffer::SamplesBuffer<i16> { | |
match std::fs::File::open(filename) { | |
Ok(mut file) => { | |
let mut data =vec![]; | |
file.read_to_end(&mut data).unwrap(); | |
let data2= data.iter().map(|x|{x.clone() as i16}).collect::<Vec<i16>>(); | |
rodio::buffer::SamplesBuffer::new(16,44100,data2)}, | |
Err(_) => panic!("Can't load music."), | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment