Browse Source

Keep track of PlayerService state instead of restarting it before closing

Signed-off-by: Álvaro Brey Vilas <alvaro.brey@nextcloud.com>
Álvaro Brey Vilas 3 years ago
parent
commit
a6f3bdceeb
1 changed files with 7 additions and 3 deletions
  1. 7 3
      src/main/java/com/nextcloud/client/media/PlayerService.kt

+ 7 - 3
src/main/java/com/nextcloud/client/media/PlayerService.kt

@@ -91,6 +91,7 @@ class PlayerService : Service() {
 
 
     private lateinit var player: Player
     private lateinit var player: Player
     private lateinit var notificationBuilder: NotificationCompat.Builder
     private lateinit var notificationBuilder: NotificationCompat.Builder
+    private var isRunning = false
 
 
     override fun onCreate() {
     override fun onCreate() {
         super.onCreate()
         super.onCreate()
@@ -169,6 +170,7 @@ class PlayerService : Service() {
         }
         }
 
 
         startForeground(R.string.media_notif_ticker, notificationBuilder.build())
         startForeground(R.string.media_notif_ticker, notificationBuilder.build())
+        isRunning = true
     }
     }
 
 
     private fun stopServiceAndRemoveNotification(file: OCFile?) {
     private fun stopServiceAndRemoveNotification(file: OCFile?) {
@@ -178,8 +180,10 @@ class PlayerService : Service() {
             player.stop(file)
             player.stop(file)
         }
         }
 
 
-        startForeground(R.string.media_notif_ticker, notificationBuilder.build())
-        stopForeground(true)
-        stopSelf();
+        if (isRunning) {
+            stopForeground(true)
+            stopSelf()
+            isRunning = false
+        }
     }
     }
 }
 }