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)]
|
||||
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: (),
|
||||
#[property(type = bool, get = Self::mute, set = Self::set_mute)]
|
||||
_mute: (),
|
||||
|
@ -102,6 +102,8 @@ mod imp {
|
|||
|
||||
// "Useful to drain property changes before a new file is loaded."
|
||||
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 {
|
||||
state: Cell::new(State::Idle),
|
||||
|
@ -354,27 +356,15 @@ mod imp {
|
|||
}
|
||||
|
||||
fn duration(&self) -> f64 {
|
||||
let duration = match self.mpv.get_property::<f64>("duration") {
|
||||
Ok(duration) => Ok(Some(duration)),
|
||||
Err(err) if err.is_property_unavailable() => {
|
||||
Ok(self.song().as_ref().map(|song| song.duration() as f64))
|
||||
}
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
.unwrap();
|
||||
match self.state.get() {
|
||||
State::Idle => 0.0,
|
||||
|
||||
{
|
||||
let left = duration.map(|f| f as i64);
|
||||
let right = self.song().as_ref().map(crate::model::Song::duration);
|
||||
if left != right {
|
||||
event!(
|
||||
Level::WARN,
|
||||
"mpv duration {left:?} doesn not match subsonic duration {right:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
State::FileLoading | State::FileEnded => self.song().unwrap().duration() as f64,
|
||||
|
||||
duration.unwrap_or(0.0) // placeholder
|
||||
State::FileLoaded | State::Active | State::Seeking => {
|
||||
self.mpv.get_property::<f64>("duration").unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn idle_active(&self) -> bool {
|
||||
|
@ -461,18 +451,11 @@ mod imp {
|
|||
}
|
||||
|
||||
fn on_hook(&self, event: crate::mpv::event::HookEvent) {
|
||||
match event.reply_userdata {
|
||||
0 => {
|
||||
assert_eq!(&event.name, "on_before_start_file");
|
||||
event!(Level::DEBUG, "on_before_start_file triggered");
|
||||
event!(Level::DEBUG, "{} hook triggered", event.name);
|
||||
// just use this as a barrier
|
||||
self.mpv.continue_hook(event.id).unwrap();
|
||||
}
|
||||
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn on_log_message(&self, event: crate::mpv::event::LogMessageEvent) {
|
||||
let span = span!(Level::DEBUG, "mpv_log", prefix = event.prefix);
|
||||
let _guard = span.enter();
|
||||
|
@ -575,6 +558,17 @@ mod imp {
|
|||
self.mpv.get_property::<String>("path").unwrap(),
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue