GstPlayer's first media-info-updated comes with 0 duration
The first time GstPlayer signals media-info-updated
, the media info usually has duration = 0. This breaks GTK 4 MediaFile because it expects that media info is set once and never changed: https://gitlab.gnome.org/GNOME/gtk/-/issues/3914
Here's a Rust reproducer based on the player.rs
example where I only added connect_media_info_updated
=> print duration:
use std::sync::{Arc, Mutex};
use gstreamer as gst;
use gstreamer_player as gst_player;
use gst::{glib, prelude::*};
fn main() {
gst::init().unwrap();
let main_loop = glib::MainLoop::new(None, false);
let dispatcher = gst_player::PlayerGMainContextSignalDispatcher::new(None);
let player = gst_player::Player::new(
None,
Some(&dispatcher.upcast::<gst_player::PlayerSignalDispatcher>()),
);
// Tell the player what uri to play.
player.set_uri("file:///home/yalter/out.webm");
player.connect_media_info_updated(|player, _| {
println!("media-info-updated, media info duration: {:?}", player.get_media_info().unwrap().get_duration());
});
let error = Arc::new(Mutex::new(Ok(())));
let main_loop_clone = main_loop.clone();
// Connect to the player's "end-of-stream" signal, which will tell us when the
// currently played media stream reached its end.
player.connect_end_of_stream(move |player| {
let main_loop = &main_loop_clone;
player.stop();
main_loop.quit();
});
let main_loop_clone = main_loop.clone();
let error_clone = Arc::clone(&error);
// Connect to the player's "error" signal, which will inform us about eventual
// errors (such as failing to retrieve a http stream).
player.connect_error(move |player, err| {
let main_loop = &main_loop_clone;
let error = &error_clone;
*error.lock().unwrap() = Err(err.clone());
player.stop();
main_loop.quit();
});
player.play();
main_loop.run();
let guard = error.as_ref().lock().unwrap();
guard.clone().unwrap();
}
On both GStreamer 1.18.4 (Fedora 34) and 1.16.3 (org.gnome.Platform
) I get something like this as an output:
media-info-updated, media info duration: ClockTime(Some(0))
media-info-updated, media info duration: ClockTime(Some(77650000000))
or
media-info-updated, media info duration: ClockTime(Some(0))
media-info-updated, media info duration: ClockTime(Some(47984000000))
media-info-updated, media info duration: ClockTime(Some(47984000000))
media-info-updated, media info duration: ClockTime(Some(47984000000))
media-info-updated, media info duration: ClockTime(Some(47984000000))
media-info-updated, media info duration: ClockTime(Some(47984000000))
media-info-updated, media info duration: ClockTime(Some(47984000000))
I suppose GstPlayer should delay the first media-info-updated
until the duration (and other flags GTK 4 uses) is known (or it's known that they won't be known).