From 36d6734e739af0ce049ec231d4bb9f66f5e9c7ed Mon Sep 17 00:00:00 2001 From: Erica Z Date: Sat, 26 Oct 2024 09:20:25 +0200 Subject: [PATCH] stop playback immediately on window close --- src/playbin.vala | 9 +++++++++ src/ui/window.vala | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/src/playbin.vala b/src/playbin.vala index c0fc546..dcb4b4d 100644 --- a/src/playbin.vala +++ b/src/playbin.vala @@ -362,6 +362,15 @@ public class Playbin : GLib.Object { } } + public void stop () { + debug ("stopping playback"); + // don't clear the playlist, just in case (less state changes to sync) + assert(this.mpv.command({"stop", "keep-playlist"}) >= 0); + this.state = PlaybinState.STOPPED; + this.play_queue_position = this._play_queue.get_n_items (); + this.stopped (); + } + ~Playbin () { debug ("destroying playbin"); } diff --git a/src/ui/window.vala b/src/ui/window.vala index 91bb496..cd0dd09 100644 --- a/src/ui/window.vala +++ b/src/ui/window.vala @@ -116,6 +116,12 @@ class Ui.Window : Adw.ApplicationWindow { return stack_child != "play-queue"; } + public override bool close_request () { + // stop playback on close + this.playbin.stop (); + return false; + } + ~Window () { debug ("destroying main window"); }