Media Session Service and IMA Ads (AdsLoader)
@marcbaechinger is already working on this.
Since Aug 14, 2024.
- Dominant language
- Java
- Stars
- 3k
- Forks
- 955
- Avg merge
- 12d 14h
- Merged PRs (30d)
- 2
Description
I'm working with the Media3 library in Android development and have encountered an issue related to the construction of AdsLoader and the recommended approach for enabling background playback by keeping an ExoPlayer instance within a MediaSessionService.
Background
I am developing an application that allows users to watch videos and listen to music, both of which should be capable of playing in the background. I decided to implement the approach outlined in the official Android developer guide for background playback using MediaSessionService. In my implementation, the ExoPlayer instance is housed within the MediaSessionService.
For example, I have a PlayerActivity that binds to the PlaybackService using the following code:
kotlin
controllerFuture = MediaController.Builder(
this,
SessionToken(this, ComponentName(this, PlaybackService::class.java))
).buildAsync()
Within the PlaybackService, the ExoPlayer instance is initialized using the onCreate method. This setup works well until I attempt to integrate ads using the IMA SDK. Configuring the IMA SDK requires constructing an AdsLoader with an AdViewProvider. However, it's not feasible to do this directly within a Service. Since the ExoPlayer instance resides within the service, it complicates the ability to provide the AdViewProvider at the PlayerActivity level. Additionally, the AdViewProvider cannot be altered once the AdsLoader is constructed. Passing a null value results in audio-only ads, meaning video ads wouldn't be displayed within the PlayerActivity.
Problem Statement
My challenge is to configure the IMA SDK and AdViewProvider to enable video ad playback when PlayerActivity is active while maintaining the ability to perform background playback using MediaSessionService and session management. Despite my efforts, I have yet to find a clear solution to this issue.
Request for Assistance
I am seeking advice on how to overcome this limitation, ideally from others who have encountered and addressed similar issues or who have a deep understanding of the Media3 library and its capabilities. Any insights or suggestions on how to effectively manage AdViewProvider configuration in this context would be greatly appreciated.
I saw a closed conversation here https://github.com/androidx/media/issues/118. But can you provide a solution if the library has provided or if we can do any hacky solution to do that?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.