From 0391911e3ecfe2e7c10b0e3db952de4889c42055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Sun, 12 Nov 2023 11:22:14 +0100 Subject: [PATCH] video-player: Only play when the player is mapped --- src/components/video_player.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/components/video_player.rs b/src/components/video_player.rs index 2a52656f..838d5d44 100644 --- a/src/components/video_player.rs +++ b/src/components/video_player.rs @@ -111,7 +111,17 @@ mod imp { } } - impl WidgetImpl for VideoPlayer {} + impl WidgetImpl for VideoPlayer { + fn map(&self) { + self.parent_map(); + self.player.play(); + } + + fn unmap(&self) { + self.player.stop(); + self.parent_unmap(); + } + } impl BinImpl for VideoPlayer {} } @@ -155,7 +165,6 @@ impl VideoPlayer { let player = self.player(); player.set_uri(Some(file.uri().as_ref())); player.set_audio_track_enabled(false); - player.play(); } fn duration_changed(&self, duration: Option) {