extern crate mpv ;
use std::env;
use std::path::Path;
fn simple_example(video_path: &Path) {
let mut mpv_builder = mpv::MpvHandlerBuilder::new().expect("Failed to init MPV builder");
if video_path.is_file() {
let video_path = video_path.to_str().expect("Expected a string for Path, got None");
mpv_builder.set_option("sid","no").unwrap();
mpv_builder.set_option("osc",true).unwrap();
let mut mpv = mpv_builder.build().expect("Failed to build MPV handler");
mpv.command(&["loadfile", video_path as &str])
.expect("Error loading file");
mpv.set_property("loop","2").unwrap();
mpv.set_property("speed",1.0).unwrap();
let n_loop : i64 = mpv.get_property("loop").unwrap() ;
println!("NUMBER OF LOOPS IS {}",n_loop);
'main: loop {
while let Some(event) = mpv.wait_event(0.0) {
println!("RECEIVED EVENT : {:?}", event);
match event {
mpv::Event::Shutdown | mpv::Event::Idle => {
break 'main;
}
_ => {}
};
}
}
println!("Simple mpv-rs example shutting down");
} else {
println!("A file is required; {} is not a valid file",
video_path.to_str().unwrap());
}
}
fn main() {
let args: Vec<_> = env::args().collect();
let (mpv_major_api_v,mpv_minor_api_v) = mpv::client_api_version();
println!("MPV_API_VERSION : v{}.{}",mpv_major_api_v,mpv_minor_api_v);
if args.len() < 2 {
println!("Usage: ./simple [any mp4, avi, mkv, ... file]");
} else {
let path: &Path = Path::new(&args[1]);
simple_example(path);
}
}