NPE in 'android.media.session.ISession.getController()'
Closed this issue · 3 comments
I've noticed this log in my crashlytics:
Caused by java.lang.NullPointerException
Attempt to invoke interface method 'android.media.session.ISessionController android.media.session.ISession.getController()' on a null object reference
android.media.session.MediaSession.<init> (MediaSession.java:199)
android.media.session.MediaSession.<init> (MediaSession.java:156)
android.support.v4.media.session.MediaSessionCompatApi21.createSession (MediaSessionCompatApi21.java:46)
android.support.v4.media.session.MediaSessionCompat$MediaSessionImplApi21.<init> (MediaSessionCompat.java:3380)
android.support.v4.media.session.MediaSessionCompat$MediaSessionImplApi28.<init> (MediaSessionCompat.java:3906)
android.support.v4.media.session.MediaSessionCompat.<init> (MediaSessionCompat.java:493)
android.support.v4.media.session.MediaSessionCompat.<init> (MediaSessionCompat.java:456)
android.support.v4.media.session.MediaSessionCompat.<init> (MediaSessionCompat.java:430)
com.hh.exoplayer.HHPlayerService$CustomPlayerNotificationManager.<init> (HHPlayerService.java:498)
com.hh.exoplayer.HHPlayerService$1.<init> (HHPlayerService.java:124)
com.hh.exoplayer.HHPlayerService.createNotification (HHPlayerService.java:123)
com.hh.exoplayer.HHPlayerService.onCreate (HHPlayerService.java:111)
android.app.ActivityThread.handleCreateService (ActivityThread.java:4379)
android.app.ActivityThread.access$1900 (ActivityThread.java:274)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:2112)
android.os.Handler.dispatchMessage (Handler.java:106)
android.os.Looper.loop (Looper.java:233)
android.app.ActivityThread.main (ActivityThread.java:8010)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:631)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:978)
When trying create Audio notification style within my AudioService (an Android Service which plays audio files).
I'm building that notification in this way:
MediaSessionCompat mediaSession = new MediaSessionCompat(context, context.getString(R.string.app_name));
mediaSession.setActive(true);
mediaSessionConnector = new MediaSessionConnector(mediaSession);
I'm not being able to replicate it because in every test I do I can play audios and notification is visible (and AudioService has been created successfully).
What's wrong in my code? What is the right way to prevent this and play audios within a Services in versions above API 21?
Thanks in advance!
- ExoPlayer version number - 2.9.6
- Android version - 11
- Android device - 50% samsung devices
@SungsooLim Hey, this is related to Session, can you take a look, or pass it on to the correct person? Thanks.
We have the same issue, but I'm mot sure if this is related to ExoPlayer
After some investigation we found out that the cause of this issue is an internal Android MediaSessions limit (100 sessions).
And as I wrote before, this issue is not related to ExoPlayer and can be closed.
How to reproduce
Just create 100 instances of MediaSession:
GlobalScope.launch {
repeat(200) {
val session = MediaSessionCompat(context, "Session") // Will cause a crash after 99 iterations
delay(200)
}
}
How to fix
You should release MediaSession instances that you don't need anymore.
GlobalScope.launch {
repeat(200) {
val session = MediaSessionCompat(context, "Session")
delay(200)
session.release()
}
}
Thanks to the article https://www.codeleading.com/article/71386122411/