{"record":{"id":"54fddf1757ebbb13","repo":"google/ExoPlayer","slug":"callbackmediaitem-isn-t-supported","errorCode":null,"errorMessage":"CallbackMediaItem isn't supported","messagePattern":"CallbackMediaItem isn't supported","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"extensions/media2/src/main/java/com/google/android/exoplayer2/ext/media2/DefaultMediaItemConverter.java","lineNumber":53,"sourceCode":" *\n * <p>Note that {@link #getMetadata} can be overridden to fill in additional metadata when\n * converting {@link MediaItem ExoPlayer MediaItems} to their AndroidX equivalents.\n *\n * @deprecated com.google.android.exoplayer2 is deprecated. Please migrate to androidx.media3 (which\n *     contains the same ExoPlayer code). See <a\n *     href=\"https://developer.android.com/guide/topics/media/media3/getting-started/migration-guide\">the\n *     migration guide</a> for more details, including a script to help with the migration.\n */\n@Deprecated\npublic class DefaultMediaItemConverter implements MediaItemConverter {\n\n  @Override\n  public MediaItem convertToExoPlayerMediaItem(androidx.media2.common.MediaItem media2MediaItem) {\n    if (media2MediaItem instanceof FileMediaItem) {\n      throw new IllegalStateException(\"FileMediaItem isn't supported\");\n    }\n    if (media2MediaItem instanceof CallbackMediaItem) {\n      throw new IllegalStateException(\"CallbackMediaItem isn't supported\");\n    }\n\n    @Nullable Uri uri = null;\n    @Nullable String mediaId = null;\n    @Nullable String title = null;\n    if (media2MediaItem instanceof UriMediaItem) {\n      UriMediaItem uriMediaItem = (UriMediaItem) media2MediaItem;\n      uri = uriMediaItem.getUri();\n    }\n    @Nullable androidx.media2.common.MediaMetadata metadata = media2MediaItem.getMetadata();\n    if (metadata != null) {\n      @Nullable String uriString = metadata.getString(METADATA_KEY_MEDIA_URI);\n      mediaId = metadata.getString(METADATA_KEY_MEDIA_ID);\n      if (uri == null) {\n        if (uriString != null) {\n          uri = Uri.parse(uriString);\n        } else if (mediaId != null) {\n          uri = Uri.parse(\"media2:///\" + mediaId);","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/google/ExoPlayer/blob/dd430f7053a1a3958deea3ead6a0565150c06bfc/extensions/media2/src/main/java/com/google/android/exoplayer2/ext/media2/DefaultMediaItemConverter.java#L35-L71","documentation":"DefaultMediaItemConverter.convertToExoPlayerMediaItem rejects androidx.media2 CallbackMediaItem instances with IllegalStateException. CallbackMediaItem supplies data through a DataSourceCallback rather than a URI; the ExoPlayer bridge has no way to represent an arbitrary callback as a MediaItem, so it refuses the conversion.","triggerScenarios":"Passing a media2 androidx.media2.common.CallbackMediaItem (built with CallbackMediaItem.Builder.setDataSourceCallback(...)) through any media2-to-ExoPlayer conversion path backed by DefaultMediaItemConverter — e.g. a media2 SessionPlayer implementation delegating to ExoPlayer.","commonSituations":"Apps feeding encrypted or in-memory content via DataSourceCallback in media2 and then handing the item to an ExoPlayer-backed session; migration projects assuming all media2 item flavors convert; library code that accepts generic media2 MediaItem without checking the subtype.","solutions":["Migrate to ExoPlayer/Media3 directly: implement a custom ExoPlayer DataSource (or use MediaItem.Builder with a custom Resolver/DataSource in Media3) instead of CallbackMediaItem.","If staying on media2 short-term, convert the callback into a URI-addressable source (local file or content:// provider) and use UriMediaItem.","Write a custom MediaItemConverter that maps CallbackMediaItem to a MediaItem backed by a custom DataSource registered on the player."],"exampleFix":"// before\nandroidx.media2.common.MediaItem item =\n    new CallbackMediaItem.Builder().setDataSourceCallback(callback).build(); // IllegalStateException\n\n// after\n// Register a custom DataSource for the scheme instead:\nMediaItem exoItem = MediaItem.fromUri(\"callback://mydata\");\n// and build the player with a DataSource.Factory that handles \"callback://\"","handlingStrategy":"type-guard","validationCode":"if (media2Item instanceof CallbackMediaItem) { /* back with custom DataSource instead */ }","typeGuard":"static boolean isConvertible(androidx.media2.common.MediaItem item) {\n  return item instanceof UriMediaItem;\n}","tryCatchPattern":null,"preventionTips":["Convert callback-based content to URI-addressable sources (content:// provider or local file).","Plan migration to Media3 where custom DataSources replace DataSourceCallback cleanly."],"tags":["media2","conversion","media-item","data-source","deprecated"],"backgroundTag":null,"analyzedSha":"dd430f7053a1a3958deea3ead6a0565150c06bfc","analyzedAt":"2026-08-14T12:22:02.982Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}