This PR attempts to reduce the number of ForegroundServiceDidNotStartInTimeException exceptions thrown by the system. I think they are mostly happening with third-party intents. Also added some other minor improvements.
Changes/Notes:
Call startForeground() as soon as possible
Always callstartForeground() instead of only at startup: If some intent update is fired using startForegroundService() then sometimes the service crashes with ForegroundServiceDidNotStartInTimeException even if it's in the foreground. This was the case with one of the crash logs from the play store.
Throttle frequent notification updates as in some cases the notification updates are ignored by the system leading to incomplete track info in the notification (reproducible on MIUI running android 12)
Workaround ANR by using a background thread for fetching thumbnails. When playing very long files (audiobooks etc.) the MediaMetadataRetriever takes too long to return and that causes an ANR. This means delaying the notification updates until a thumbnail result is available. This could use some work.
Save current track info on track change, previously we only did this on pause/seek/dismiss.
This PR attempts to reduce the number of
ForegroundServiceDidNotStartInTimeException
exceptions thrown by the system. I think they are mostly happening with third-party intents. Also added some other minor improvements.Changes/Notes:
startForeground()
as soon as possiblestartForeground()
instead of only at startup: If some intent update is fired usingstartForegroundService()
then sometimes the service crashes withForegroundServiceDidNotStartInTimeException
even if it's in the foreground. This was the case with one of the crash logs from the play store.