show pulsing buffering bar after 3 seconds
This commit is contained in:
parent
88962c629c
commit
38b3902f69
3 changed files with 190 additions and 146 deletions
|
@ -2,6 +2,16 @@ using Gtk 4.0;
|
||||||
using Adw 1;
|
using Adw 1;
|
||||||
|
|
||||||
template $AudreyUiPlaybar: Adw.Bin {
|
template $AudreyUiPlaybar: Adw.Bin {
|
||||||
|
child: Overlay {
|
||||||
|
[overlay]
|
||||||
|
ProgressBar pulse_bar {
|
||||||
|
styles [
|
||||||
|
"osd"
|
||||||
|
]
|
||||||
|
visible: bind template.show-pulse-bar;
|
||||||
|
valign: start;
|
||||||
|
}
|
||||||
|
|
||||||
child: CenterBox {
|
child: CenterBox {
|
||||||
hexpand: true;
|
hexpand: true;
|
||||||
|
|
||||||
|
@ -84,6 +94,7 @@ template $AudreyUiPlaybar: Adw.Bin {
|
||||||
orientation: horizontal;
|
orientation: horizontal;
|
||||||
width-request: 400;
|
width-request: 400;
|
||||||
sensitive: bind template.idle-active inverted;
|
sensitive: bind template.idle-active inverted;
|
||||||
|
|
||||||
adjustment: Adjustment {
|
adjustment: Adjustment {
|
||||||
lower: 0;
|
lower: 0;
|
||||||
value: bind template.position;
|
value: bind template.position;
|
||||||
|
@ -172,4 +183,5 @@ template $AudreyUiPlaybar: Adw.Bin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,10 @@ mod imp {
|
||||||
#[properties(wrapper_type = super::Playbar)]
|
#[properties(wrapper_type = super::Playbar)]
|
||||||
#[template(resource = "/eu/callcc/audrey/playbar.ui")]
|
#[template(resource = "/eu/callcc/audrey/playbar.ui")]
|
||||||
pub struct Playbar {
|
pub struct Playbar {
|
||||||
|
#[template_child]
|
||||||
|
#[property(get)]
|
||||||
|
pulse_bar: TemplateChild<gtk::ProgressBar>,
|
||||||
|
|
||||||
#[property(get, set)]
|
#[property(get, set)]
|
||||||
song: RefCell<Option<PlaybinSong>>,
|
song: RefCell<Option<PlaybinSong>>,
|
||||||
#[property(get, set)]
|
#[property(get, set)]
|
||||||
|
@ -34,6 +38,9 @@ mod imp {
|
||||||
position: Cell<f64>,
|
position: Cell<f64>,
|
||||||
#[property(get, set)]
|
#[property(get, set)]
|
||||||
duration: Cell<f64>,
|
duration: Cell<f64>,
|
||||||
|
|
||||||
|
#[property(get, set)]
|
||||||
|
_show_pulse_bar: Cell<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[glib::object_subclass]
|
#[glib::object_subclass]
|
||||||
|
|
|
@ -54,6 +54,8 @@ mod imp {
|
||||||
#[property(type = u32, get = Self::playlist_count)]
|
#[property(type = u32, get = Self::playlist_count)]
|
||||||
_playlist_count: (),
|
_playlist_count: (),
|
||||||
|
|
||||||
|
tick_callback: Cell<Option<gtk::TickCallbackId>>,
|
||||||
|
|
||||||
pub(super) queued_seek: Cell<Option<f64>>,
|
pub(super) queued_seek: Cell<Option<f64>>,
|
||||||
|
|
||||||
pub(crate) initial_setup_handle: RefCell<Option<JoinHandle<()>>>,
|
pub(crate) initial_setup_handle: RefCell<Option<JoinHandle<()>>>,
|
||||||
|
@ -103,7 +105,9 @@ mod imp {
|
||||||
_idle_active: (),
|
_idle_active: (),
|
||||||
_playlist_count: (),
|
_playlist_count: (),
|
||||||
|
|
||||||
queued_seek: Cell::new(None),
|
tick_callback: Default::default(),
|
||||||
|
|
||||||
|
queued_seek: Default::default(),
|
||||||
|
|
||||||
initial_setup_handle: Default::default(),
|
initial_setup_handle: Default::default(),
|
||||||
mpv_event_loop_handle: Default::default(),
|
mpv_event_loop_handle: Default::default(),
|
||||||
|
@ -202,7 +206,9 @@ mod imp {
|
||||||
},
|
},
|
||||||
|
|
||||||
Event::StartFile(_) => {
|
Event::StartFile(_) => {
|
||||||
|
event!(Level::INFO, "start file event");
|
||||||
window.notify("song");
|
window.notify("song");
|
||||||
|
window.imp().buffering_start();
|
||||||
// TODO: load cover art
|
// TODO: load cover art
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,12 +264,12 @@ mod imp {
|
||||||
|
|
||||||
Event::Seek => {
|
Event::Seek => {
|
||||||
event!(Level::INFO, "seek event");
|
event!(Level::INFO, "seek event");
|
||||||
// TODO: if doing "buffering" progress bar, show it after a timeout here
|
window.imp().buffering_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
Event::PlaybackRestart => {
|
Event::PlaybackRestart => {
|
||||||
event!(Level::INFO, "playback restart event");
|
event!(Level::INFO, "playback restart event");
|
||||||
// TODO: if doing "buffering" progress bar, hide it here
|
window.imp().buffering_end();
|
||||||
|
|
||||||
if let Some(queued_seek) = window.imp().queued_seek.take() {
|
if let Some(queued_seek) = window.imp().queued_seek.take() {
|
||||||
// a seek was tried before and failed, try again now
|
// a seek was tried before and failed, try again now
|
||||||
|
@ -478,6 +484,25 @@ mod imp {
|
||||||
Some(song)
|
Some(song)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn buffering_start(&self) {
|
||||||
|
let started_buffering = std::time::Instant::now();
|
||||||
|
self.tick_callback
|
||||||
|
.replace(Some(self.obj().add_tick_callback(move |window, _| {
|
||||||
|
// 3 second period from gnome hig
|
||||||
|
if started_buffering.elapsed() > std::time::Duration::from_secs(3) {
|
||||||
|
window.imp().playbar.set_show_pulse_bar(true);
|
||||||
|
window.imp().playbar.pulse_bar().pulse();
|
||||||
|
}
|
||||||
|
glib::ControlFlow::Continue
|
||||||
|
})))
|
||||||
|
.map(gtk::TickCallbackId::remove);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn buffering_end(&self) {
|
||||||
|
self.tick_callback.take().map(gtk::TickCallbackId::remove);
|
||||||
|
self.playbar.set_show_pulse_bar(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Window {
|
impl Drop for Window {
|
||||||
|
|
Loading…
Reference in a new issue