Swiping away demo-session while playing does not end process
@marcbaechinger is already working on this.
Since May 10, 2024.
- Dominant language
- Java
- Stars
- 3k
- Forks
- 955
- Avg merge
- 12d 14h
- Merged PRs (30d)
- 2
Description
Version
Media3 main branch
More version details
753f607a81287b798863a675b54cb8196665d95f
1.3.1
Devices that reproduce the issue
API 33 emulator
Devices that do not reproduce the issue
No response
Reproducible in the demo app?
Yes
Reproduction steps
Add the following to: DemoPlaybackService
override fun onTaskRemoved(rootIntent: Intent?) {
Log.d("DemoPlaybackService", "onTaskRemoved: ")
val player = mediaLibrarySession.player
if (player.playWhenReady) {
// Make sure the service is not in foreground.
player.pause()
}
stopSelf()
}
Play audio from the demo-session app
Background the app
Swipe away the app
video showing both pause and swipe away, and just swipe away and pause programatically:
https://github.com/androidx/media/assets/3092675/e8b3784c-0eee-4040-a43d-aaa3cda7218a
logcat logs: process-not-ended.log
adb bugreport will be mailed
Expected result
just like when you pause playback in the background manually before swiping away the process should end
Actual result
now that the pause is done programmatically when swiping away the process does not end
This means that singletons are not cleaned up between app starts and therefore states held by it leak.
I have my changes at https://github.com/TomVarga/media/tree/disabled-playback-resumption-pause-on-taks-removed
I have created a helper class to showcase the problem: object SingletonValueHolder
which has it's value set to true in PlayerActivity#initializeController and the value is printed out in MainActivity#onCreate
from the logs you can see that if I manually pause playback while in the background, then swipe away the app, then the next time I open the app the value correctly resets to false as the process ended, and a new singleton was created
However if I don't pause playback manually, but rely on onTaskRemoved to do the pause programmatically as suggested in the docs https://developer.android.com/media/media3/session/background-playback#service-lifecycle then the process is not stopped, the singleton lives alonge and next time I start the app, the value remains true as it can be seen from the printout of it at MainActivity#onCreate
If this is is not enough to stop playback and release the process, then what else needs to be done?
Media
example: Jazz & Blues in the demo-session sample app
Bug Report
- You will email the zip file produced by
adb bugreportto android-media-github@google.com after filing this issue.
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.