androidx / androidx/media

MediaSessionService Never Destroy, Once App is Cleared Without Pausing Media

Open
#1,198 11 comments 0 reactions 1 assignee View on GitHub

@marcbaechinger is already working on this.

Since Mar 19, 2024.

needs triage question
Dominant language
Java
Stars
3k
Forks
955
Avg merge
12d 14h
Merged PRs (30d)
2

Description

Version
Media3 1.2.1

When Media started to play, Now When User Close the app and Clear The Notification on this Scenario The Service never gets Destroyed.
Yeah I know we can clear Mediasession from service via onTaskRemoved but this works only when player is not playing, If Player is not playing currently and user try to close the app Then the Service get's destroyed. If Player is still running than the service won't get Destroyed,

Even I tried This Case When User Try to Close the App from onTaskRemoved I forcing the playing to stop and clear MediaSession Still Service keeps Running

override fun onTaskRemoved(rootIntent: Intent?) {
       exoPlayer.pause()
       stopSelf()
       super.onTaskRemoved(rootIntent)
   }

 private fun clearMediaSession() {
       mediaSession?.run {
           player.release()
           release()
       }
    }

   override fun onDestroy() {
       clearMediaSession()
       clearListener()
       super.onDestroy()
   }
The Same Code Before Closing the app if player is Paused Then the Server will get Destroyed if player still playing Service Wont Destroy.

The Same Functionality is happening in Media3 Demo-Session Player as well.

On This Scenario How to Destroy The Service, Due to this App Consuming More Battery!!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.