How is ondestroy managed by the MediaLibraryService in demo app
@marcbaechinger is already working on this.
Since Sep 23, 2024.
- Dominant language
- Java
- Stars
- 3k
- Forks
- 955
- Avg merge
- 12d 14h
- Merged PRs (30d)
- 2
Description
How is ondestroy managed by the MediaLibraryService in demo app
I am trying to save the last song mediaUri and currentposition of the song in Jetpack DataStore for this I am using
val uriString = player.currentMediaItem?.requestMetadata?.mediaUri
val position = player.currentPosition
how ever I found these two issues
-
When we pause the player and swipe the app to close it , the ondestroy method is called but the values for
uristringandpositionarenull -
If we have already swiped the app , yet the player is playing using the service and notification, if we now pause the song and swipe the notification away ondestroy is called after a long time mostly 30 seconds to 1 minute.
I have tested it on samsung Galaxy Tab A7 Lite
Android version 14
This issue occured on this device mediauri is null for the first issue , some times the second issue occur but the ondestroy was called after a really long time like 1 minute after the app service was closed using the notification and the mediauri is null .
However testing on Pixel 3A Api 34 there were issues like we dont get the uri was null and position was 0 in the first issue and on destroy takes a long time for the second issue but we get the uri and the position
On Android pixel 2 Api 26 both issues didnot occur however ondestroy took a long time for the second issue.
It seems to be device specific issue , however samsung dominates the android device market so, Is there a solution for this,
Please test this issue on devices other than pixel where mostly all the issues are resolved.
To Reproduce the issue just add following code to the demo app here
Log.d("ondestroy", "ondestroy")
val uriString = mediaLibrarySession.player.currentMediaItem?.requestMetadata?.mediaUri
val position = mediaLibrarySession.player.currentPosition
Log.d("uriString position", "uriString $uriString position $position")
It seems a API 34 or above level issue specially if we pause the player and swipe it away we dont get either the mediauri and the position at all. they return null and 0 respectively.
I have not tested on other api level other than those mentioned above.
and follow above two steps to reproduce each issue separately.
I want to save the currentposition and uri as string using the datastore, how can we achieve this if ondestroy has above issues, is there any work around to do this, I have tried to save the current uri using the player.addListener(object : Player.Listener {}) but I assume it must be not an efficient way in case the user skips to previous and next songs in a speedy manner and there is no way to save the current position unless we use ondestroy,
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.