mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-29 04:51:09 +00:00
Add basic-tutorial-1 from the GStreamer tutorials
https://cgit.freedesktop.org/gstreamer/gst-docs/tree/examples/tutorials/basic-tutorial-1.c
This commit is contained in:
parent
7dfab61390
commit
6f6db8ac47
3 changed files with 54 additions and 0 deletions
|
@ -7,4 +7,5 @@ members = [
|
||||||
"gstreamer-player",
|
"gstreamer-player",
|
||||||
"gstreamer-video",
|
"gstreamer-video",
|
||||||
"examples",
|
"examples",
|
||||||
|
"tutorials",
|
||||||
]
|
]
|
||||||
|
|
11
tutorials/Cargo.toml
Normal file
11
tutorials/Cargo.toml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
[package]
|
||||||
|
name = "tutorials"
|
||||||
|
version = "0.9.0"
|
||||||
|
authors = ["Sebastian Dröge <sebastian@centricular.com>"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
glib = { version = "0.3", git = "https://github.com/gtk-rs/glib" }
|
||||||
|
gstreamer = { path = "../gstreamer" }
|
||||||
|
|
||||||
|
[badges]
|
||||||
|
travis-ci = { repository = "sdroege/gstreamer-rs", branch = "master" }
|
42
tutorials/src/bin/basic-tutorial-1.rs
Normal file
42
tutorials/src/bin/basic-tutorial-1.rs
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
extern crate gstreamer as gst;
|
||||||
|
use gst::prelude::*;
|
||||||
|
|
||||||
|
use std::u64;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
gst::init().unwrap();
|
||||||
|
|
||||||
|
let uri = "https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm";
|
||||||
|
let pipeline = gst::parse_launch(&format!("playbin uri={}", uri)).unwrap();
|
||||||
|
|
||||||
|
let ret = pipeline.set_state(gst::State::Playing);
|
||||||
|
assert_ne!(ret, gst::StateChangeReturn::Failure);
|
||||||
|
|
||||||
|
let bus = pipeline.get_bus().unwrap();
|
||||||
|
|
||||||
|
loop {
|
||||||
|
use gst::MessageView;
|
||||||
|
|
||||||
|
let msg = match bus.timed_pop(u64::MAX) {
|
||||||
|
None => break,
|
||||||
|
Some(msg) => msg,
|
||||||
|
};
|
||||||
|
|
||||||
|
match msg.view() {
|
||||||
|
MessageView::Eos(..) => break,
|
||||||
|
MessageView::Error(err) => {
|
||||||
|
println!(
|
||||||
|
"Error from {}: {} ({:?})",
|
||||||
|
msg.get_src().get_path_string(),
|
||||||
|
err.get_error(),
|
||||||
|
err.get_debug()
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let ret = pipeline.set_state(gst::State::Null);
|
||||||
|
assert_ne!(ret, gst::StateChangeReturn::Failure);
|
||||||
|
}
|
Loading…
Reference in a new issue