2017-09-08 08:51:27 +00:00
|
|
|
use gst::prelude::*;
|
|
|
|
|
2017-11-12 13:53:50 +00:00
|
|
|
#[path = "../tutorials-common.rs"]
|
|
|
|
mod tutorials_common;
|
|
|
|
|
|
|
|
fn tutorial_main() {
|
2017-09-08 13:33:09 +00:00
|
|
|
// Initialize GStreamer
|
2017-09-08 08:51:27 +00:00
|
|
|
gst::init().unwrap();
|
|
|
|
|
2017-09-08 13:33:09 +00:00
|
|
|
// Build the pipeline
|
2017-10-17 09:06:51 +00:00
|
|
|
let uri =
|
|
|
|
"https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm";
|
2017-09-08 08:51:27 +00:00
|
|
|
let pipeline = gst::parse_launch(&format!("playbin uri={}", uri)).unwrap();
|
|
|
|
|
2017-09-08 13:33:09 +00:00
|
|
|
// Start playing
|
2019-01-08 16:13:37 +00:00
|
|
|
pipeline
|
|
|
|
.set_state(gst::State::Playing)
|
|
|
|
.expect("Unable to set the pipeline to the `Playing` state");
|
2017-09-08 08:51:27 +00:00
|
|
|
|
2017-09-08 13:33:09 +00:00
|
|
|
// Wait until error or EOS
|
2021-04-11 19:39:50 +00:00
|
|
|
let bus = pipeline.bus().unwrap();
|
2021-04-28 22:29:13 +00:00
|
|
|
for msg in bus.iter_timed(gst::ClockTime::NONE) {
|
2017-09-08 08:51:27 +00:00
|
|
|
use gst::MessageView;
|
|
|
|
|
|
|
|
match msg.view() {
|
|
|
|
MessageView::Eos(..) => break,
|
|
|
|
MessageView::Error(err) => {
|
|
|
|
println!(
|
2017-11-16 11:58:56 +00:00
|
|
|
"Error from {:?}: {} ({:?})",
|
2021-04-11 19:39:50 +00:00
|
|
|
err.src().map(|s| s.path_string()),
|
|
|
|
err.error(),
|
|
|
|
err.debug()
|
2017-09-08 08:51:27 +00:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-08 13:33:09 +00:00
|
|
|
// Shutdown pipeline
|
2019-01-08 16:13:37 +00:00
|
|
|
pipeline
|
|
|
|
.set_state(gst::State::Null)
|
|
|
|
.expect("Unable to set the pipeline to the `Null` state");
|
2017-09-08 08:51:27 +00:00
|
|
|
}
|
2017-11-12 13:53:50 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// tutorials_common::run is only required to set up the application environment on macOS
|
|
|
|
// (but not necessary in normal Cocoa applications where this is set up automatically)
|
|
|
|
tutorials_common::run(tutorial_main);
|
|
|
|
}
|