google/ExoPlayer · error · IllegalStateException
FileMediaItem isn't supported
Error message
FileMediaItem isn't supported
What it means
DefaultMediaItemConverter.convertToExoPlayerMediaItem rejects androidx.media2 FileMediaItem instances with IllegalStateException. The media2 bridge only knows how to convert URI-addressable items (UriMediaItem); FileMediaItem carries file descriptors/endpoints it has no mapping for, so conversion is explicitly unsupported rather than silently degraded.
Source
Thrown at extensions/media2/src/main/java/com/google/android/exoplayer2/ext/media2/DefaultMediaItemConverter.java:50
/**
* Default implementation of {@link MediaItemConverter}.
*
* <p>Note that {@link #getMetadata} can be overridden to fill in additional metadata when
* converting {@link MediaItem ExoPlayer MediaItems} to their AndroidX equivalents.
*
* @deprecated com.google.android.exoplayer2 is deprecated. Please migrate to androidx.media3 (which
* contains the same ExoPlayer code). See <a
* href="https://developer.android.com/guide/topics/media/media3/getting-started/migration-guide">the
* migration guide</a> for more details, including a script to help with the migration.
*/
@Deprecated
public class DefaultMediaItemConverter implements MediaItemConverter {
@Override
public MediaItem convertToExoPlayerMediaItem(androidx.media2.common.MediaItem media2MediaItem) {
if (media2MediaItem instanceof FileMediaItem) {
throw new IllegalStateException("FileMediaItem isn't supported");
}
if (media2MediaItem instanceof CallbackMediaItem) {
throw new IllegalStateException("CallbackMediaItem isn't supported");
}
@Nullable Uri uri = null;
@Nullable String mediaId = null;
@Nullable String title = null;
if (media2MediaItem instanceof UriMediaItem) {
UriMediaItem uriMediaItem = (UriMediaItem) media2MediaItem;
uri = uriMediaItem.getUri();
}
@Nullable androidx.media2.common.MediaMetadata metadata = media2MediaItem.getMetadata();
if (metadata != null) {
@Nullable String uriString = metadata.getString(METADATA_KEY_MEDIA_URI);
mediaId = metadata.getString(METADATA_KEY_MEDIA_ID);
if (uri == null) {
if (uriString != null) {View on GitHub (pinned to dd430f7053)
Solutions
- Replace FileMediaItem with UriMediaItem built from Uri.fromFile(file) (or a file:// URI) so the converter can map it.
- Better: migrate off the deprecated media2 bridge entirely — convert your data model to ExoPlayer/Media3 MediaItem directly (MediaItem.fromUri / fromFile), since com.google.android.exoplayer2 is deprecated in favor of androidx.media3.
- If you must keep media2, implement a custom MediaItemConverter that handles FileMediaItem by extracting the file path and producing MediaItem.fromUri.
Example fix
// before
androidx.media2.common.MediaItem item =
new FileMediaItem.Builder(file).build(); // IllegalStateException in converter
// after
androidx.media2.common.MediaItem item =
new UriMediaItem.Builder(Uri.fromFile(file)).build(); // convertible Defensive patterns
Strategy: type-guard
Validate before calling
if (media2Item instanceof FileMediaItem) { /* convert manually */ } Type guard
static boolean isConvertible(androidx.media2.common.MediaItem item) {
return item instanceof UriMediaItem; // only UriMediaItem converts cleanly
} Prevention
- Only feed UriMediaItem into DefaultMediaItemConverter.
- Migrate off the deprecated media2 bridge to Media3 MediaItem.
When it happens
Trigger: Passing a media2 androidx.media2.common.FileMediaItem (e.g. created via FileMediaItem.Builder) into SessionPlayer/mediaplayer pipelines backed by ExoPlayer through this converter — i.e. any media2 API surface that funnels MediaItems into an ExoPlayer-based player.
Common situations: Migrating an app from media2 SessionPlayer to ExoPlayer while reusing existing FileMediaItem-creating code; media2 widgets (MediaLibrarySession callbacks) handing back FileMediaItem; assuming 'MediaItem' in media2 and ExoPlayer are interchangeable types.
Related errors
AI-assisted analysis of google/ExoPlayer@dd430f7053 (2026-08-14).
Data as JSON: /api/errors/ebd2baefe899eb84.
Report an issue: GitHub.