fast4x / RiMusic

A multilingual Android application for streaming music from YouTube Music.
https://rimusic.xyz
GNU General Public License v3.0
2.6k stars 132 forks source link

Bug fix for app crash when persistant queue is enabled #4496

Closed Abhinavreddy-B closed 1 week ago

Abhinavreddy-B commented 1 week ago

Refer this issue #4492 for full details on the bug and the fix.

this is a resource I found online: https://stackoverflow.com/questions/44425584/context-startforegroundservice-did-not-then-call-service-startforeground

From what I understood, the startForegroundService is only required when the app wants to push a notification, and the catch is the app has to start notification within 5 seconds of calling startForegroundService.

In this piece of code:

runCatching {
                    ContextCompat.startForegroundService(
                        this@PlayerServiceModern,
                        intent<PlayerServiceModern>()
                    )
                }.onFailure {
                    Timber.e("maybeRestorePlayerQueue startForegroundService ${it.stackTraceToString()}")
                }

The app is unnecessarily calling startForegroundService because it is never creating a notification from here. the notification logic seems to somewhere else and independent of this. Since notification is not being started within 5 seconds, the OS things its an ANR and closes the app.

On removing this code snippet, the bug got fixed for me. so I think this is the issue.

This code might have ended up here while refactoring the notification logic, because originally in PlayerService.kt, notification logic was immediately after this code snippet.

please correct me if am wrong

fast4x commented 1 week ago

No fix it's correct, this code is unnecessary, i've just removed yesterday, but thanks for your fix.