Skip to content

Commit

Permalink
Merge pull request #195 from hasezoey/updateGstreamer
Browse files Browse the repository at this point in the history
Update dependencies `gstreamer` and `glib`
  • Loading branch information
tramhao authored Jan 24, 2024
2 parents 52e24d3 + 4fb679e commit 50e64f0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 46 deletions.
82 changes: 50 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ escaper = "0.1.1"
figment = { version = "0.10", features = ["toml"] }
futures = "0.3"
futures-util = "0.3"
glib = { version = "0.17" }
gstreamer = { version = "0.20" }
glib = { version = "0.18" }
gstreamer = { version = "0.21" }
hex = "0.4"
id3 = "1"
image = "0.24"
Expand Down
26 changes: 14 additions & 12 deletions playback/src/gstreamer_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use super::{PlayerCmd, PlayerTrait};
use anyhow::Result;
use async_trait::async_trait;
use glib::{FlagsClass, MainContext};
use gst::bus::BusWatchGuard;
use gst::ClockTime;
use gst::{event::Seek, Element, SeekFlags, SeekType};
use gstreamer as gst;
Expand Down Expand Up @@ -53,7 +54,6 @@ impl PathToURI for Path {
}
}

#[derive(Clone)]
pub struct GStreamer {
playbin: Element,
paused: bool,
Expand All @@ -64,6 +64,7 @@ pub struct GStreamer {
pub position: Arc<Mutex<i64>>,
pub duration: Arc<Mutex<i64>>,
pub radio_title: Arc<Mutex<String>>,
_bus_watch_guard: BusWatchGuard,
}

#[allow(clippy::cast_lossless)]
Expand Down Expand Up @@ -108,7 +109,7 @@ impl GStreamer {
playbin.set_property("audio-sink", &sink);
// Set flags to show Audio and Video but ignore Subtitles
let flags = playbin.property_value("flags");
let flags_class = FlagsClass::new(flags.type_()).unwrap();
let flags_class = FlagsClass::with_type(flags.type_()).unwrap();

let flags = flags_class
.builder_with_value(flags)
Expand All @@ -129,7 +130,7 @@ impl GStreamer {

let radio_title = Arc::new(Mutex::new(String::new()));
let radio_title_internal = radio_title.clone();
playbin
let bus_watch = playbin
.bus()
.expect("Failed to get GStreamer message bus")
.add_watch(glib::clone!(@strong main_tx => move |_bus, msg| {
Expand Down Expand Up @@ -176,7 +177,7 @@ impl GStreamer {
// }
_ => (),
}
glib::Continue(true)
glib::ControlFlow::Continue
}))
.expect("Failed to connect to GStreamer message bus");

Expand All @@ -186,7 +187,7 @@ impl GStreamer {
None,
glib::clone!(@strong mainloop => move |msg| {
tx.send(msg).ok();
glib::Continue(true)
glib::ControlFlow::Continue
}),
);
mainloop.run();
Expand All @@ -206,6 +207,7 @@ impl GStreamer {
position: Arc::new(Mutex::new(0_i64)),
duration,
radio_title,
_bus_watch_guard: bus_watch,
};

this.set_volume(volume);
Expand All @@ -227,13 +229,13 @@ impl GStreamer {
None
});

glib::source::timeout_add(
std::time::Duration::from_millis(1000),
glib::clone!(@strong this => move || {
this.get_progress().ok();
glib::Continue(true)
}),
);
// glib::source::timeout_add(
// std::time::Duration::from_millis(1000),
// glib::clone!(@strong this => move || {
// this.get_progress().ok();
// glib::ControlFlow::Continue
// }),
// );

this
}
Expand Down

0 comments on commit 50e64f0

Please sign in to comment.