Try to suppress crashes because of startForegroundService

Sometimes, this method is called before the app is in foreground resulting in crash because of A12 foreground limitations, so we try to catch the exception
This commit is contained in:
Prathamesh More 2022-04-29 17:09:03 +05:30
parent 8cd3fcfd38
commit 8b5b6d0e64

View file

@ -132,8 +132,10 @@ object MusicPlayerRemote : KoinComponent {
try {
contextWrapper.startService(intent)
} catch (ignored: IllegalStateException) {
runCatching {
ContextCompat.startForegroundService(context, intent)
}
}
val binder = ServiceBinder(callback)
if (contextWrapper.bindService(
@ -260,7 +262,7 @@ object MusicPlayerRemote : KoinComponent {
private fun tryToHandleOpenPlayingQueue(
queue: List<Song>,
startPosition: Int,
startPlaying: Boolean
startPlaying: Boolean,
): Boolean {
if (playingQueue === queue) {
if (startPlaying) {