Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Randomly crash on android #19

Open
soramister opened this issue Nov 18, 2023 · 4 comments
Open

Randomly crash on android #19

soramister opened this issue Nov 18, 2023 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@soramister
Copy link
Contributor

Hello,

I have been having random crash on first update of the MediaSession.

I have created the following PR which fix the issue :
#18

I don't know why it happened by the variables in this PR were null, which crashes the application. I have added a check to be sure it is not null. This prevent the crash.

There must be a better way to fix it, but I found this one does.

Let me know if you have any questions.

@webmasterab
Copy link

Good that there is a solution.
I would like an update so that this can be resolved with the next update of the app that uses this.

@jofr
Copy link
Owner

jofr commented Jan 21, 2024

Thank you for the fix @soramister, it is now merged and a new version of the plugin has been published. I'll leave this issue open to further investigate why those variables are null (for which I don't have the time right now).

@jofr jofr self-assigned this Jan 21, 2024
@jofr jofr added the bug Something isn't working label Jan 21, 2024
@zsilbi
Copy link

zsilbi commented Mar 14, 2024

I have experienced some random crashes too when the media I try to play has issues.
The player handles the error, but might sends the events too rapidly causing the internal state to be inconsistent.

This one can be solved by adding additional null checks: #22

FATAL EXCEPTION: main
java.lang.NullPointerException: Attempt to invoke virtual method 'void io.github.jofr.capacitor.mediasessionplugin.MediaSessionService.setTitle(java.lang.String)' on a null object reference
	at io.github.jofr.capacitor.mediasessionplugin.MediaSessionPlugin.updateServiceMetadata(MediaSessionPlugin.java:91)
	at io.github.jofr.capacitor.mediasessionplugin.MediaSessionPlugin.-$$Nest$mupdateServiceMetadata(Unknown Source:0)
	at io.github.jofr.capacitor.mediasessionplugin.MediaSessionPlugin$1.onServiceConnected(MediaSessionPlugin.java:59)
	at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:2188)
	at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:2221)
	at android.os.Handler.handleCallback(Handler.java:942)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loopOnce(Looper.java:201)
	at android.os.Looper.loop(Looper.java:288)
	at android.app.ActivityThread.main(ActivityThread.java:7872)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

This one is not so straightforward..

FATAL EXCEPTION: main
android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{c984139 u0 io.github.jofr.capacitor.mediasessionplugin.MediaSessionService}
	at android.app.ActivityThread.generateForegroundServiceDidNotStartInTimeException(ActivityThread.java:2005)
	at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:1976)
	at android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException(Unknown Source:0)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2241)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loopOnce(Looper.java:201)
	at android.os.Looper.loop(Looper.java:288)
	at android.app.ActivityThread.main(ActivityThread.java:7872)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

@fabian-meisinger
Copy link

I recently started using this plugin and see the following crash reported in Crashlytics:

Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'boolean io.github.jofr.capacitor.mediasessionplugin.MediaSessionPlugin.hasActionHandler(java.lang.String)' on a null object reference
       at io.github.jofr.capacitor.mediasessionplugin.MediaSessionService.update(MediaSessionService.java:233)
       at io.github.jofr.capacitor.mediasessionplugin.MediaSessionService.updatePossibleActions(MediaSessionService.java:301)
       at io.github.jofr.capacitor.mediasessionplugin.MediaSessionPlugin.setActionHandler(MediaSessionPlugin.java:195)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138)
       at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:774)
       at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA()
       at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(:8)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:226)
       at android.os.Looper.loop(Looper.java:313)
       at android.os.HandlerThread.run(HandlerThread.java:67)

From the looks of it this seems to be a threading issue and MediaSessionService.update sometimes gets called before MediaSessionService.connectAndInitialize has finished. Otherwise I don't know why plugin would be null in that line.
Maybe you could move the assignment of this.plugin to the end of connectAndInitialize and use it to determine if the service has fully initialized by checking if plugin is null before running anything else in the update method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants