Skip to content

Commit

Permalink
fix(trackplayer): Applied fix for background error (doublesymmetry/re…
Browse files Browse the repository at this point in the history
  • Loading branch information
S. Jansen committed Apr 15, 2024
1 parent dcb5c4c commit 5dfc0f0
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions patches/react-native-track-player+4.0.1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
diff --git a/node_modules/react-native-track-player/android/src/main/java/com/doublesymmetry/trackplayer/service/MusicService.kt b/node_modules/react-native-track-player/android/src/main/java/com/doublesymmetry/trackplayer/service/MusicService.kt
index 9d6d869..cb49aa6 100644
--- a/node_modules/react-native-track-player/android/src/main/java/com/doublesymmetry/trackplayer/service/MusicService.kt
+++ b/node_modules/react-native-track-player/android/src/main/java/com/doublesymmetry/trackplayer/service/MusicService.kt
@@ -120,9 +120,17 @@ class MusicService : HeadlessJsTaskService() {
notificationBuilder.foregroundServiceBehavior = NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE
}
val notification = notificationBuilder.build()
- startForeground(EMPTY_NOTIFICATION_ID, notification)
- @Suppress("DEPRECATION")
- stopForeground(true)
+ try {
+ // reference exception catch of startForegroundIfNecessary function
+ startForeground(EMPTY_NOTIFICATION_ID, notification)
+ @Suppress("DEPRECATION")
+ stopForeground(true)
+ } catch (error: Exception) {
+ Timber.e(
+ "ForegroundServiceStartNotAllowedException: App tried to start a foreground Service when it was not allowed to do so.",
+ error
+ )
+ }
}

@MainThread

0 comments on commit 5dfc0f0

Please sign in to comment.