vlc-rs/examples/cli_player.rs

46 lines
1.1 KiB
Rust
Raw Permalink Normal View History

2015-11-29 08:30:19 +00:00
// This file is an example for vlc-rs, licensed under CC0.
// https://creativecommons.org/publicdomain/zero/1.0/deed
extern crate vlc;
use std::sync::mpsc::channel;
use vlc::{Event, EventType, Instance, Media, MediaPlayer, State};
2015-11-29 08:30:19 +00:00
fn main() {
let args: Vec<String> = std::env::args().collect();
let path = match args.get(1) {
Some(s) => s,
None => {
println!("Usage: cli_audio_player path_to_a_media_file");
return;
}
};
let instance = Instance::new().unwrap();
let md = Media::new_path(&instance, path).unwrap();
2015-11-29 08:30:19 +00:00
let mdp = MediaPlayer::new(&instance).unwrap();
2015-11-29 08:30:19 +00:00
let (tx, rx) = channel::<()>();
2015-11-29 08:30:19 +00:00
let em = md.event_manager();
let _ = em.attach(EventType::MediaStateChanged, move |e, _| match e {
Event::MediaStateChanged(s) => {
println!("State : {:?}", s);
if s == State::Ended || s == State::Error {
tx.send(()).unwrap();
}
2015-11-29 08:30:19 +00:00
}
_ => (),
2015-11-29 08:30:19 +00:00
});
2015-11-29 08:30:19 +00:00
mdp.set_media(&md);
2015-11-29 08:30:19 +00:00
// Start playing
mdp.play().unwrap();
2015-11-29 08:30:19 +00:00
// Wait for end state
rx.recv().unwrap();
2015-11-29 08:30:19 +00:00
}