2017-07-31 15:24:30 +00:00
|
|
|
extern crate gstreamer as gst;
|
2017-08-17 14:58:15 +00:00
|
|
|
use gst::prelude::*;
|
2017-07-31 15:24:30 +00:00
|
|
|
|
|
|
|
extern crate glib;
|
|
|
|
|
|
|
|
use std::env;
|
|
|
|
|
2017-11-12 18:07:02 +00:00
|
|
|
#[path = "../examples-common.rs"]
|
|
|
|
mod examples_common;
|
|
|
|
|
|
|
|
fn example_main() {
|
2017-07-31 15:24:30 +00:00
|
|
|
gst::init().unwrap();
|
|
|
|
|
|
|
|
let args: Vec<_> = env::args().collect();
|
|
|
|
let uri: &str = if args.len() == 2 {
|
|
|
|
args[1].as_ref()
|
|
|
|
} else {
|
2017-11-10 15:53:32 +00:00
|
|
|
println!("Usage: playbin uri");
|
2017-11-27 11:01:03 +00:00
|
|
|
std::process::exit(-1)
|
2017-07-31 15:24:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let playbin = gst::ElementFactory::make("playbin", None).unwrap();
|
2017-08-17 14:58:15 +00:00
|
|
|
playbin
|
|
|
|
.set_property("uri", &glib::Value::from(uri))
|
|
|
|
.unwrap();
|
2017-07-31 15:24:30 +00:00
|
|
|
|
|
|
|
// For flags handling
|
|
|
|
// let flags = playbin.get_property("flags").unwrap();
|
|
|
|
// let flags_class = FlagsClass::new(flags.type_()).unwrap();
|
|
|
|
// let flags = flags_class.builder_with_value(flags).unwrap()
|
|
|
|
// .unset_by_nick("text")
|
|
|
|
// .unset_by_nick("video")
|
|
|
|
// .build()
|
|
|
|
// .unwrap();
|
|
|
|
// playbin.set_property("flags", &flags).unwrap();
|
|
|
|
|
2017-08-11 12:31:59 +00:00
|
|
|
playbin
|
|
|
|
.connect("audio-tags-changed", false, |values| {
|
|
|
|
let playbin = values[0].get::<glib::Object>().unwrap();
|
|
|
|
let idx = values[1].get::<i32>().unwrap();
|
|
|
|
|
|
|
|
println!("audio tags of audio stream {} changed:", idx);
|
|
|
|
|
|
|
|
let tags = playbin
|
|
|
|
.emit("get-audio-tags", &[&idx.to_value()])
|
|
|
|
.unwrap()
|
|
|
|
.unwrap();
|
2017-08-17 14:58:15 +00:00
|
|
|
let tags = tags.get::<gst::TagList>().unwrap();
|
2017-08-11 12:31:59 +00:00
|
|
|
|
2017-08-17 14:58:15 +00:00
|
|
|
if let Some(artist) = tags.get::<gst::tags::Artist>() {
|
2017-08-11 12:31:59 +00:00
|
|
|
println!(" Artist: {}", artist.get().unwrap());
|
|
|
|
}
|
|
|
|
|
2017-08-17 14:58:15 +00:00
|
|
|
if let Some(title) = tags.get::<gst::tags::Title>() {
|
2017-08-11 12:31:59 +00:00
|
|
|
println!(" Title: {}", title.get().unwrap());
|
|
|
|
}
|
|
|
|
|
2017-08-17 14:58:15 +00:00
|
|
|
if let Some(album) = tags.get::<gst::tags::Album>() {
|
2017-08-11 12:31:59 +00:00
|
|
|
println!(" Album: {}", album.get().unwrap());
|
|
|
|
}
|
|
|
|
|
|
|
|
None
|
2018-10-08 12:02:23 +00:00
|
|
|
})
|
|
|
|
.unwrap();
|
2017-08-11 12:31:59 +00:00
|
|
|
|
2017-07-31 15:24:30 +00:00
|
|
|
let bus = playbin.get_bus().unwrap();
|
|
|
|
|
|
|
|
let ret = playbin.set_state(gst::State::Playing);
|
|
|
|
assert_ne!(ret, gst::StateChangeReturn::Failure);
|
|
|
|
|
2017-09-13 16:35:35 +00:00
|
|
|
while let Some(msg) = bus.timed_pop(gst::CLOCK_TIME_NONE) {
|
2017-08-17 14:58:15 +00:00
|
|
|
use gst::MessageView;
|
|
|
|
|
2017-07-31 15:24:30 +00:00
|
|
|
match msg.view() {
|
|
|
|
MessageView::Eos(..) => break,
|
|
|
|
MessageView::Error(err) => {
|
|
|
|
println!(
|
2017-11-16 11:58:56 +00:00
|
|
|
"Error from {:?}: {} ({:?})",
|
2018-01-29 12:25:12 +00:00
|
|
|
err.get_src().map(|s| s.get_path_string()),
|
2017-07-31 15:24:30 +00:00
|
|
|
err.get_error(),
|
|
|
|
err.get_debug()
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let ret = playbin.set_state(gst::State::Null);
|
|
|
|
assert_ne!(ret, gst::StateChangeReturn::Failure);
|
|
|
|
}
|
2017-11-12 18:07:02 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// tutorials_common::run is only required to set up the application environent on macOS
|
|
|
|
// (but not necessary in normal Cocoa applications where this is set up autmatically)
|
|
|
|
examples_common::run(example_main);
|
|
|
|
}
|