androidx / androidx/media

MediaSource reuse and BaseMediaSource releaseSource.

Open
#2,263 6 comments 0 reactions 1 assignee View on GitHub

@marcbaechinger is already working on this.

Since Mar 24, 2025.

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

Description

To prepare for some requested features for my application I now have to manage multiple instance of ExoPlayer 1.6.0.

There's cases where I will prepare a player for a mediaSource but then have to release that player.
In that case when I try to reuse the mediaSource in another player there's an error (See below).
This is because the mediaSource was already prepared and have a looper associated that will be different from the new player.

The release of the player is done via:

clearMediaItems() 
stop() 
playbackParameters = PlaybackParameters.DEFAULT 
removeListener(customEventListener)
release()

I tried to retrace how / if the releaseSource is called in that case but code is hard to follow.

Is it normal that the looper is not reset in that case? Is there something I can do to ensure that it is ?

PS:

  1. Each player have it's own looper for performance reasons, ANRs and not using MainThread.
  2. The media source preparation is costly so it would be best if I could reuse it.

Error:

ExoAnalyticsLogger.e@62: ExoPlayerImplInternal - Playback error (Ask Gemini)
androidx.media3.exoplayer.ExoPlaybackException: Unexpected runtime error
	at androidx.media3.exoplayer.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:849)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loopOnce(Looper.java:248)
	at android.os.Looper.loop(Looper.java:338)
	at android.os.HandlerThread.run(HandlerThread.java:85)
Caused by: java.lang.IllegalArgumentException
	at androidx.media3.common.util.Assertions.checkArgument(Assertions.java:40)
	at androidx.media3.exoplayer.source.BaseMediaSource.prepareSource(BaseMediaSource.java:248)
	at androidx.media3.exoplayer.source.CompositeMediaSource.prepareChildSource(CompositeMediaSource.java:123)
	at androidx.media3.exoplayer.source.WrappingMediaSource.prepareChildSource(WrappingMediaSource.java:240)
	at androidx.media3.exoplayer.source.MaskingMediaSource.createPeriod(MaskingMediaSource.java:127)
	at androidx.media3.exoplayer.MediaSourceList.createPeriod(MediaSourceList.java:338)
	at androidx.media3.exoplayer.MediaPeriodHolder.createMediaPeriod(MediaPeriodHolder.java:498)
	at androidx.media3.exoplayer.MediaPeriodHolder.<init>(MediaPeriodHolder.java:126)
	at androidx.media3.exoplayer.ExoPlayerImplInternal.createMediaPeriodHolder(ExoPlayerImplInternal.java:354)
	at androidx.media3.exoplayer.ExoPlayerImplInternal.$r8$lambda$4ByVomVrDZGMrfXELlhTrFd0naQ(Unknown Source:0)
	at androidx.media3.exoplayer.ExoPlayerImplInternal$$ExternalSyntheticLambda2.create(D8$$SyntheticClass:0)
	at androidx.media3.exoplayer.MediaPeriodQueue.enqueueNextMediaPeriodHolder(MediaPeriodQueue.java:227)
	at androidx.media3.exoplayer.ExoPlayerImplInternal.maybeUpdateLoadingPeriod(ExoPlayerImplInternal.java:2474)
	at androidx.media3.exoplayer.ExoPlayerImplInternal.updatePeriods(ExoPlayerImplInternal.java:2459)
	at androidx.media3.exoplayer.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:1295)
	at androidx.media3.exoplayer.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:646)
	at android.os.Handler.dispatchMessage(Handler.java:106) 
	at android.os.Looper.loopOnce(Looper.java:248) 
	at android.os.Looper.loop(Looper.java:338) 
	at android.os.HandlerThread.run(HandlerThread.java:85) 

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.