From ed8b7c0d97b335fd641bfd38f7f04d2add6def41 Mon Sep 17 00:00:00 2001 From: Elias Projahn Date: Sun, 10 Oct 2021 20:35:54 +0200 Subject: [PATCH] Fix crash in player by caching the duration --- backend/src/player.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/src/player.rs b/backend/src/player.rs index 8eaf0fc..f471423 100644 --- a/backend/src/player.rs +++ b/backend/src/player.rs @@ -16,6 +16,7 @@ pub struct Player { playlist: RefCell>, current_track: Cell>, playing: Cell, + duration: Cell, playlist_cbs: RefCell)>>>, track_cbs: RefCell>>, duration_cbs: RefCell>>, @@ -42,6 +43,7 @@ impl Player { playlist: RefCell::new(Vec::new()), current_track: Cell::new(None), playing: Cell::new(false), + duration: Cell::new(0), playlist_cbs: RefCell::new(Vec::new()), track_cbs: RefCell::new(Vec::new()), duration_cbs: RefCell::new(Vec::new()), @@ -95,7 +97,9 @@ impl Player { let clone = fragile::Fragile::new(result.clone()); player.connect_duration_changed(move |_, duration| { for cb in &*clone.get().duration_cbs.borrow() { - cb(duration.unwrap().mseconds()); + let duration = duration.unwrap().mseconds(); + clone.get().duration.set(duration); + cb(duration); } }); @@ -353,7 +357,7 @@ impl Player { } for cb in &*self.duration_cbs.borrow() { - cb(self.player.duration().unwrap().mseconds()); + cb(self.duration.get()); } for cb in &*self.playing_cbs.borrow() {