jofr / capacitor-media-session

Capacitor plugin for media notifications and platform media keys as well as background audio playback.
GNU General Public License v3.0
36 stars 25 forks source link

Android Crashes Fatal Exception: android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException #24

Open AEiosApp opened 7 months ago

AEiosApp commented 7 months ago

Recently updated plugin to version 3.0.2 and in the Firebase crashlytics can see that 8 users had crashes with this logs:

Fatal Exception: android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{7c8a25b u0 com.ae.touringbee/io.github.jofr.capacitor.mediasessionplugin.MediaSessionService}

Fatal Exception: android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{7c8a25b u0 com.ae.touringbee/io.github.jofr.capacitor.mediasessionplugin.MediaSessionService}
       at android.app.ActivityThread.generateForegroundServiceDidNotStartInTimeException(ActivityThread.java:2315)
       at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2286)
       at android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException()
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2611)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loopOnce(Looper.java:230)
       at android.os.Looper.loop(Looper.java:319)
       at android.app.ActivityThread.main(ActivityThread.java:8893)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)

Caused by android.app.StackTrace Last startServiceCommon() call for this service was made here


Caused by android.app.StackTrace: Last startServiceCommon() call for this service was made here
       at android.app.ContextImpl.startServiceCommon(ContextImpl.java:2023)
       at android.app.ContextImpl.startForegroundService(ContextImpl.java:1967)
       at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:847)
       at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:847)
       at androidx.core.content.ContextCompat$Api26Impl.startForegroundService(ContextCompat.java:1091)
       at androidx.core.content.ContextCompat.startForegroundService(ContextCompat.java:749)
       at androidx.media.session.MediaButtonReceiver.onReceive(MediaButtonReceiver.java:115)
       at android.app.ActivityThread.handleReceiver(ActivityThread.java:4896)
       at android.app.ActivityThread.-$$Nest$mhandleReceiver()
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2498)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loopOnce(Looper.java:230)
       at android.os.Looper.loop(Looper.java:319)
       at android.app.ActivityThread.main(ActivityThread.java:8893)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
matthewbal commented 7 months ago

We've had the same issue, were you able to fix this by downgrading?

AEiosApp commented 7 months ago

@matthewbal no, was you able to fix your issue by downgrading? If yes, to which version?

matthewbal commented 7 months ago

Unfortunately not, we've decided to opt for a native player plugin so that we have more granular control over background play. On IOS it is impossible to start a foreground service from the background, so we need to use native there anyway.

We're implementing a plugin similar to the one mentioned in this forum post.

https://forum.ionicframework.com/t/audio-in-the-background-for-ionic-capacitor-app/234073