uhhh
This commit is contained in:
parent
57b6024845
commit
c4f17817e4
1 changed files with 23 additions and 29 deletions
|
@ -53,7 +53,7 @@ mod imp {
|
||||||
#[property(get)]
|
#[property(get)]
|
||||||
albums_model: gio::ListStore,
|
albums_model: gio::ListStore,
|
||||||
|
|
||||||
#[property(type = i64, get = Self::volume, set = Self::set_volume, minimum = 0, maximum = 100)]
|
#[property(type = i64, get = Self::volume, set = Self::set_volume)]
|
||||||
_volume: (),
|
_volume: (),
|
||||||
#[property(type = bool, get = Self::mute, set = Self::set_mute)]
|
#[property(type = bool, get = Self::mute, set = Self::set_mute)]
|
||||||
_mute: (),
|
_mute: (),
|
||||||
|
@ -102,6 +102,8 @@ mod imp {
|
||||||
|
|
||||||
// "Useful to drain property changes before a new file is loaded."
|
// "Useful to drain property changes before a new file is loaded."
|
||||||
mpv.add_hook(0, "on_before_start_file", 0).unwrap();
|
mpv.add_hook(0, "on_before_start_file", 0).unwrap();
|
||||||
|
// "Useful to drain property changes after a file has finished."
|
||||||
|
mpv.add_hook(0, "o_after_start_file", 0).unwrap();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
state: Cell::new(State::Idle),
|
state: Cell::new(State::Idle),
|
||||||
|
@ -354,27 +356,15 @@ mod imp {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn duration(&self) -> f64 {
|
fn duration(&self) -> f64 {
|
||||||
let duration = match self.mpv.get_property::<f64>("duration") {
|
match self.state.get() {
|
||||||
Ok(duration) => Ok(Some(duration)),
|
State::Idle => 0.0,
|
||||||
Err(err) if err.is_property_unavailable() => {
|
|
||||||
Ok(self.song().as_ref().map(|song| song.duration() as f64))
|
|
||||||
}
|
|
||||||
Err(err) => Err(err),
|
|
||||||
}
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
{
|
State::FileLoading | State::FileEnded => self.song().unwrap().duration() as f64,
|
||||||
let left = duration.map(|f| f as i64);
|
|
||||||
let right = self.song().as_ref().map(crate::model::Song::duration);
|
State::FileLoaded | State::Active | State::Seeking => {
|
||||||
if left != right {
|
self.mpv.get_property::<f64>("duration").unwrap()
|
||||||
event!(
|
|
||||||
Level::WARN,
|
|
||||||
"mpv duration {left:?} doesn not match subsonic duration {right:?}"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
duration.unwrap_or(0.0) // placeholder
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn idle_active(&self) -> bool {
|
fn idle_active(&self) -> bool {
|
||||||
|
@ -461,16 +451,9 @@ mod imp {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_hook(&self, event: crate::mpv::event::HookEvent) {
|
fn on_hook(&self, event: crate::mpv::event::HookEvent) {
|
||||||
match event.reply_userdata {
|
event!(Level::DEBUG, "{} hook triggered", event.name);
|
||||||
0 => {
|
// just use this as a barrier
|
||||||
assert_eq!(&event.name, "on_before_start_file");
|
self.mpv.continue_hook(event.id).unwrap();
|
||||||
event!(Level::DEBUG, "on_before_start_file triggered");
|
|
||||||
// just use this as a barrier
|
|
||||||
self.mpv.continue_hook(event.id).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_log_message(&self, event: crate::mpv::event::LogMessageEvent) {
|
fn on_log_message(&self, event: crate::mpv::event::LogMessageEvent) {
|
||||||
|
@ -575,6 +558,17 @@ mod imp {
|
||||||
self.mpv.get_property::<String>("path").unwrap(),
|
self.mpv.get_property::<String>("path").unwrap(),
|
||||||
self.obj().song().unwrap().stream_url()
|
self.obj().song().unwrap().stream_url()
|
||||||
);
|
);
|
||||||
|
// same with "duration"
|
||||||
|
{
|
||||||
|
let left = self.mpv.get_property::<f64>("duration").unwrap() as i64;
|
||||||
|
let right = self.song().unwrap().duration();
|
||||||
|
if left != right {
|
||||||
|
event!(
|
||||||
|
Level::WARN,
|
||||||
|
"mpv duration {left:?} doesn not match subsonic duration {right:?}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_seek(&self) {
|
fn on_seek(&self) {
|
||||||
|
|
Loading…
Reference in a new issue