androidx / media

Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android
https://developer.android.com/media/media3
Apache License 2.0
1.56k stars 373 forks source link

Context.startForegroundService() did not then call Service.startForeground() #1709

Open BoikoIlya opened 1 week ago

BoikoIlya commented 1 week ago

Version

Media3 1.3.1

More version details

No response

Devices that reproduce the issue

image

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

n/d

Expected result

do not crash

Actual result

Fatal Exception: android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{3f60406 u0 com.kamancho.melisma/.player.presentation.PlayerService}
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2126)
   at android.os.Handler.dispatchMessage(Handler.java:106)
   at android.os.Looper.loop(Looper.java:236)
   at android.app.ActivityThread.main(ActivityThread.java:8057)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)

my service class

class PlayerService: MediaSessionService(){

@Inject
lateinit var player: ExoPlayer

@Inject
lateinit var mediaSession: MediaSession

override fun onCreate() {
    super.onCreate()

    (this.applicationContext as App).appComponent
        .playerComponent()
        .build()
        .inject(this)
}

override fun onGetSession(controllerInfo: MediaSession.ControllerInfo): MediaSession = mediaSession

override fun onTaskRemoved(rootIntent: Intent?) {
    if (!mediaSession.player.playWhenReady) {
         stopSelf()
    }
}

override fun onDestroy() {
    player.release()
    mediaSession.release()
    super.onDestroy()
}

}

Media

n/d

Bug Report

BoikoIlya commented 1 week ago
image
marcbaechinger commented 1 week ago

Thanks for your report.

I think there isn't sufficient information for us to do something. Can you repro this with the demo app? If so, please provide the steps to reproduce with the demo app.

If this isn't possible, then it's probably an app issue. If you want me to give my opinion on what the reason may be, then you should provide us with some more information, for instance how the service is started when it fails.