From 262b5d77c1887da01da666183c4519c7ce9d353c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Felix=20Paul=20K=C3=BChne?= <felix@feepk.net>
Date: Wed, 10 May 2023 12:56:14 +0200
Subject: [PATCH] AppDelegate: save playback position on termination if
 playback is active

(cherry picked from commit 1b2a48b652d5fd34d33d161887832bed2d1a90d2)
---
 Sources/App/iOS/VLCAppDelegate.m | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/Sources/App/iOS/VLCAppDelegate.m b/Sources/App/iOS/VLCAppDelegate.m
index 8f0f23a0d..d9b42c2b2 100644
--- a/Sources/App/iOS/VLCAppDelegate.m
+++ b/Sources/App/iOS/VLCAppDelegate.m
@@ -2,7 +2,7 @@
  * VLCAppDelegate.m
  * VLC for iOS
  *****************************************************************************
- * Copyright (c) 2013-2022 VideoLAN. All rights reserved.
+ * Copyright (c) 2013-2023 VideoLAN. All rights reserved.
  * $Id$
  *
  * Authors: Felix Paul Kühne <fkuehne # videolan.org>
@@ -229,6 +229,16 @@
     }
 }
 
+- (void)applicationWillTerminate:(UIApplication *)application
+{
+    /* save the playback position before the user kills the app */
+    VLCPlaybackService *vps = [VLCPlaybackService sharedInstance];
+    if (vps.isPlaying || vps.playerIsSetup) {
+        VLCAppCoordinator *appCoordinator = [VLCAppCoordinator sharedInstance];
+        [appCoordinator.mediaLibraryService savePlaybackStateFrom:vps];
+    }
+}
+
 - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler
 {
     [[VLCAppCoordinator sharedInstance] handleShortcutItem:shortcutItem];
-- 
GitLab