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.72k stars 413 forks source link

Pass the context to shouldStartForegroundService #1887

Closed johngray1965 closed 3 days ago

johngray1965 commented 1 week ago

[REQUIRED] Use case description

In order to implement androidx.media3.session.MediaButtonReceiver.shouldStartForegroundService, I need to inject something. I can either use @AndroidEntryPoint or use @EntryPoint. The former doesn't work because the dagger generated code overrides onReceive and androidx.media3.session.MediaButtonReceiver implementation of onReceive is final. The latter doesn't because I don't have context needed to use the @EntryPoint.

Proposed solution

Where the androidx.media3.session.MediaButtonReceiver calls shouldStartForegroundService, it has a context. In fact it uses when it calls ContextCompat.startForegroundService, in order to correctly implement shouldStartForegroundService I need same information.

Alternatives considered

Copying the code from androidx.media3.session.MediaButtonReceiver to implement my own (not a great option).

Note, this is with 1.5.0-rc01

marcbaechinger commented 1 week ago

Yup, that is a valid request. Thanks for the suggestion. We will pass the context, we get in onReceive to shouldStartForegroundService. We will update this issue when this lands in the main branch.

johngray1965 commented 1 week ago

Yup, that is a valid request. Thanks for the suggestion. We will pass the context, we get in onReceive to shouldStartForegroundService. We will update this issue when this lands in the main branch.

Thank you. That'll be very helpful.

marcbaechinger commented 3 days ago

The change is available in main and will be included in the next release. Thanks for the suggestion!