Composable APIs are error-prone when creating Player in composition
@oceanjules is already working on this.
Since Mar 31, 2025.
- Dominant language
- Java
- Stars
- 3k
- Forks
- 955
- Avg merge
- 12d 14h
- Merged PRs (30d)
- 2
Description
Version
Media3 pre-release (alpha, beta or RC not in this list)
More version details
1.6.0-RC02
Devices that reproduce the issue
N/A
Devices that do not reproduce the issue
No response
Reproducible in the demo app?
Yes
Reproduction steps
The current state of Compose support in Media3 appears to mislead developers into unsafe Composable usage patterns. My understanding of the Player contract is that Player.release() should always be called at some point after Player construction. This kind of pattern is not well-supported by common Compose constructs (remember), as it implies some sort of side effect from construction, that must be remedied by another side effect. There are various ways to work around this situation cleanly, but it's generally error-prone and/or cumbersome.
Media3 could add rememberPlayer(factory: () -> Player): Player, which might leverage RememberObserver behind the scenes to appropriately call dispose() when leaving the composition.
Expected result
N/A
Actual result
N/A
Media
N/A
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.