Skip to content

Commit

Permalink
fix: start foreground android version
Browse files Browse the repository at this point in the history
  • Loading branch information
lovegaoshi committed Jan 30, 2024
1 parent 0577029 commit 1145e2d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,17 @@ class MusicService : HeadlessJsMediaService() {
notificationBuilder.foregroundServiceBehavior = NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE
}
val notification = notificationBuilder.build()
startForeground(EMPTY_NOTIFICATION_ID, notification)
@Suppress("DEPRECATION")
stopForeground(true)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
startForeground(EMPTY_NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK)
} else {
startForeground(EMPTY_NOTIFICATION_ID, notification)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
stopForeground(STOP_FOREGROUND_REMOVE)
} else {
@Suppress("DEPRECATION")
stopForeground(true)
}
}

@MainThread
Expand Down Expand Up @@ -924,7 +932,6 @@ class MusicService : HeadlessJsMediaService() {
@MainThread
override fun onTaskRemoved(rootIntent: Intent?) {
super.onTaskRemoved(rootIntent)

if (!::player.isInitialized) return

when (appKilledPlaybackBehavior) {
Expand Down
4 changes: 2 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ buildscript {
ext {
buildToolsVersion = "33.0.0"
minSdkVersion = 21
compileSdkVersion = 33
targetSdkVersion = 33
compileSdkVersion = 34
targetSdkVersion = 34

// We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
ndkVersion = "23.1.7779620"
Expand Down

0 comments on commit 1145e2d

Please sign in to comment.