Skip to content

Commit

Permalink
test fix for fgs crash
Browse files Browse the repository at this point in the history
Update MusicService.kt
  • Loading branch information
mikooomich authored and reocat committed Jan 30, 2025
1 parent 60719a6 commit aa056b8
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion app/src/main/java/com/dd3boh/outertune/playback/MusicService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ import android.app.PendingIntent
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK
import android.database.SQLException
import android.media.audiofx.AudioEffect
import android.net.ConnectivityManager
import android.net.Uri
import android.os.Binder
import android.os.Build
import android.widget.Toast
import androidx.core.app.NotificationChannelCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.getSystemService
import androidx.core.net.toUri
import androidx.datastore.preferences.core.edit
Expand Down Expand Up @@ -193,6 +197,7 @@ class MusicService : MediaLibraryService(),

lateinit var player: ExoPlayer
private lateinit var mediaSession: MediaLibrarySession
private lateinit var notificationManager: NotificationManagerCompat
private lateinit var playerNotificationManager: PlayerNotificationManager

private var isAudioEffectSessionOpened = false
Expand Down Expand Up @@ -471,12 +476,31 @@ class MusicService : MediaLibraryService(),
}
}
}

notificationManager = NotificationManagerCompat.from(this)
notificationManager.createNotificationChannel(
NotificationChannelCompat.Builder(
CHANNEL_ID, NotificationManagerCompat.IMPORTANCE_HIGH
).apply {
setName("why google why")
setVibrationEnabled(true)
setVibrationPattern(longArrayOf(0L, 200L))
setLightsEnabled(false)
setShowBadge(false)
setSound(null, null)
}.build()
)

playerNotificationManager = PlayerNotificationManager.Builder(this, NOTIFICATION_ID, CHANNEL_ID)
.setNotificationListener(object : PlayerNotificationManager.NotificationListener {
override fun onNotificationPosted(notificationId: Int, notification: Notification, ongoing: Boolean) {
// FG keep alive
if (dataStore.get(KeepAliveKey, false)) {
startForeground(notificationId, notification)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
startForeground(notificationId, notification, FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK)
} else {
startForeground(notificationId, notification)
}
} else {
stopForeground(notificationId)
}
Expand Down

0 comments on commit aa056b8

Please sign in to comment.