[fractal] media-viewer: Fix video not stopping after closing



commit 3f6370fd571d6f5aac61f97cfd9de951bafa1931
Author: Marco Melorio <marco melorio protonmail com>
Date:   Tue Aug 23 19:58:22 2022 +0200

    media-viewer: Fix video not stopping after closing
    
    This was implemented in MediaViewer, but it wasn't working because of
    wrong hierarchy navigation. I've fixed this by adding a function to do
    that in MediaContentViewer directly.
    
    Part-of: <https://gitlab.gnome.org/GNOME/fractal/-/merge_requests/1135>

 src/components/media_content_viewer.rs | 15 +++++++++++++++
 src/session/media_viewer.rs            | 13 +------------
 2 files changed, 16 insertions(+), 12 deletions(-)
---
diff --git a/src/components/media_content_viewer.rs b/src/components/media_content_viewer.rs
index dc4bbc7e7..807a06b22 100644
--- a/src/components/media_content_viewer.rs
+++ b/src/components/media_content_viewer.rs
@@ -129,6 +129,21 @@ impl MediaContentViewer {
         glib::Object::new(&[("autoplay", &autoplay)]).expect("Failed to create MediaContentViewer")
     }
 
+    pub fn stop_playback(&self) {
+        if let Some(stream) = self
+            .imp()
+            .viewer
+            .child()
+            .and_then(|c| c.downcast::<gtk::Video>().ok())
+            .and_then(|v| v.media_stream())
+        {
+            if stream.is_playing() {
+                stream.pause();
+                stream.seek(0);
+            }
+        }
+    }
+
     pub fn autoplay(&self) -> bool {
         self.imp().autoplay.get()
     }
diff --git a/src/session/media_viewer.rs b/src/session/media_viewer.rs
index 3f67d5560..e0bf4804b 100644
--- a/src/session/media_viewer.rs
+++ b/src/session/media_viewer.rs
@@ -49,18 +49,7 @@ mod imp {
                     obj.activate_action("win.toggle-fullscreen", None).unwrap();
                 }
 
-                if let Some(stream) = obj
-                    .imp()
-                    .media
-                    .child()
-                    .and_then(|w| w.downcast::<gtk::Video>().ok())
-                    .and_then(|video| video.media_stream())
-                {
-                    if stream.is_playing() {
-                        stream.pause();
-                        stream.seek(0);
-                    }
-                }
+                obj.imp().media.stop_playback();
                 obj.activate_action("session.show-content", None).unwrap();
             });
             klass.add_binding_action(


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]