androidx / androidx/media

Essentially reopening issue#2048, caching DrmSessions

Open
#3,020 0 comments 0 reactions 1 assignee View on GitHub

@icbaker is already working on this.

Since Jan 21, 2026.

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

Description

Use case description

Need to cache DrmSession objects to avoid multiple license fetches for channel changes.

Proposed solution

The original solution was proposed in pull request: https://github.com/androidx/media/pull/2049

Alternatives considered

An alternative was suggested by @icbaker in #2048, however the solution needs tuning.

The suggestion was good, implement the cache in a custom DrmSessionManagerProvider. In order to force caching the DrmSession the balance of DrmSessionManager.prepare() to DrmSessionManager.release() needs to be controlled, issuing one additional prepare() call to preserve the DrmSession's in the session keep alive cache.

The only problem with the solution,

...
  @Override
  public DrmSessionManager get(MediaItem mediaItem) {
    DrmSessionManager drmSessionManager = delegate.get(mediaItem);
    if (cachedManagers.add(drmSessionManager)) {
      drmSessionManager.prepare();
    }
...

It is not possible to call prepare() from this method, it is called when the MediaSource is created, on the main application thread. The call needs to be on a player thread.

I'm sure there are ways to make this happen, the best choice for doing so is not clear to me.

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.