From a02354278adf1039349f2d673efd3e454f28e87e Mon Sep 17 00:00:00 2001 From: "T. Okubo" Date: Sun, 29 Nov 2015 17:30:19 +0900 Subject: [PATCH] Add examples --- README.md | 4 +++- examples/cli_player.rs | 50 +++++++++++++++++++++++++++++++++++++++ examples/print_version.rs | 10 ++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 examples/cli_player.rs create mode 100644 examples/print_version.rs diff --git a/README.md b/README.md index f9a5e3b..0cc67ef 100644 --- a/README.md +++ b/README.md @@ -36,5 +36,7 @@ fn main() { } ``` +Other examples are in the examples directory. + ## License -MIT +MIT (Examples are licensed under CC0) diff --git a/examples/cli_player.rs b/examples/cli_player.rs new file mode 100644 index 0000000..8cc9d92 --- /dev/null +++ b/examples/cli_player.rs @@ -0,0 +1,50 @@ + +// 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::{Instance, Media, MediaPlayer, Event, EventType, State}; + +fn main() { + let args: Vec = 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(); + let mdp = MediaPlayer::new(&instance).unwrap(); + + let (tx, rx) = channel::<()>(); + + 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(); + } + }, + _ => (), + } + }); + + mdp.set_media(&md); + + // Start playing + mdp.play().unwrap(); + + // Wait for end state + rx.recv().unwrap(); +} + + diff --git a/examples/print_version.rs b/examples/print_version.rs new file mode 100644 index 0000000..7e1909e --- /dev/null +++ b/examples/print_version.rs @@ -0,0 +1,10 @@ + +// This file is an example for vlc-rs, licensed under CC0. +// https://creativecommons.org/publicdomain/zero/1.0/deed + +extern crate vlc; + +fn main() { + println!("Version : {}", vlc::version()); + println!("Compiler : {}", vlc::compiler()); +}