androidx / androidx/media

Composable APIs are error-prone when creating Player in composition

Open
#2,270 4 comments 0 reactions 1 assignee View on GitHub

@oceanjules is already working on this.

Since Mar 31, 2025.

bug enhancement
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 bugreport to android-media-github@google.com after filing this issue.

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.