examples/tutorials: The get-XXX-tags signals on playbin can return a None taglist

This commit is contained in:
Sebastian Dröge 2021-11-21 18:38:39 +02:00
parent 1ffcea4da7
commit 27613a8901
3 changed files with 50 additions and 40 deletions

View file

@ -75,8 +75,9 @@ fn example_main() {
// application is via properties, signals or action signals (or custom messages, events, queries).
// So what the following code does, is essentially asking playbin to tell us its already
// internally stored tag list for this stream index.
let tags = playbin.emit_by_name::<gst::TagList>("get-audio-tags", &[&idx]);
let tags = playbin.emit_by_name::<Option<gst::TagList>>("get-audio-tags", &[&idx]);
if let Some(tags) = tags {
if let Some(artist) = tags.get::<gst::tags::Artist>() {
println!(" Artist: {}", artist.get());
}
@ -88,6 +89,7 @@ fn example_main() {
if let Some(album) = tags.get::<gst::tags::Album>() {
println!(" Album: {}", album.get());
}
}
None
});

View file

@ -42,8 +42,9 @@ mod tutorial5 {
let x = playbin.property::<i32>(propname);
for i in 0..x {
let tags = playbin.emit_by_name::<gst::TagList>(signame, &[&i]);
let tags = playbin.emit_by_name::<Option<gst::TagList>>(signame, &[&i]);
if let Some(tags) = tags {
textbuf.insert_at_cursor(&format!("{} stream {}:\n ", stype, i));
if let Some(codec) = tags.get::<gst::tags::VideoCodec>() {
@ -63,6 +64,7 @@ mod tutorial5 {
}
}
}
}
// Extract metadata from all the streams and write it to the text widget in the GUI
fn analyze_streams(playbin: &gst::Element, textbuf: &gtk::TextBuffer) {

View file

@ -21,17 +21,20 @@ fn analyze_streams(playbin: &gst::Element) {
);
for i in 0..n_video {
let tags = playbin.emit_by_name::<gst::TagList>("get-video-tags", &[&i]);
let tags = playbin.emit_by_name::<Option<gst::TagList>>("get-video-tags", &[&i]);
if let Some(tags) = tags {
println!("video stream {}:", i);
if let Some(codec) = tags.get::<gst::tags::VideoCodec>() {
println!(" codec: {}", codec.get());
}
}
}
for i in 0..n_audio {
let tags = playbin.emit_by_name::<gst::TagList>("get-audio-tags", &[&i]);
let tags = playbin.emit_by_name::<Option<gst::TagList>>("get-audio-tags", &[&i]);
if let Some(tags) = tags {
println!("audio stream {}:", i);
if let Some(codec) = tags.get::<gst::tags::AudioCodec>() {
println!(" codec: {}", codec.get());
@ -43,15 +46,18 @@ fn analyze_streams(playbin: &gst::Element) {
println!(" bitrate: {}", codec.get());
}
}
}
for i in 0..n_text {
let tags = playbin.emit_by_name::<gst::TagList>("get-text-tags", &[&i]);
let tags = playbin.emit_by_name::<Option<gst::TagList>>("get-text-tags", &[&i]);
if let Some(tags) = tags {
println!("subtitle stream {}:", i);
if let Some(codec) = tags.get::<gst::tags::LanguageCode>() {
println!(" language: {}", codec.get());
}
}
}
let current_video = playbin.property::<i32>("current-video");
let current_audio = playbin.property::<i32>("current-audio");