google/ExoPlayer · error · IllegalArgumentException

Unsupported stream format:${format}

Error message

Unsupported stream format:${format}

What it means

Thrown by ImaServerSideAdInsertionUriBuilder.createStreamRequest when the FORMAT query parameter, parsed as an integer, is neither C.CONTENT_TYPE_DASH nor C.CONTENT_TYPE_HLS. The IMA DAI SDK only serves those two stream formats, so any other value cannot be mapped to a StreamRequest.

Source

Thrown at extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/ImaServerSideAdInsertionUriBuilder.java:357

    // Required params.
    @Nullable String assetKey = uri.getQueryParameter(ASSET_KEY);
    @Nullable String apiKey = uri.getQueryParameter(API_KEY);
    @Nullable String contentSourceId = uri.getQueryParameter(CONTENT_SOURCE_ID);
    @Nullable String videoId = uri.getQueryParameter(VIDEO_ID);
    if (!TextUtils.isEmpty(assetKey)) {
      streamRequest = ImaSdkFactory.getInstance().createLiveStreamRequest(assetKey, apiKey);
    } else {
      streamRequest =
          ImaSdkFactory.getInstance()
              .createVodStreamRequest(checkNotNull(contentSourceId), checkNotNull(videoId), apiKey);
    }
    int format = Integer.parseInt(uri.getQueryParameter(FORMAT));
    if (format == C.CONTENT_TYPE_DASH) {
      streamRequest.setFormat(StreamFormat.DASH);
    } else if (format == C.CONTENT_TYPE_HLS) {
      streamRequest.setFormat(StreamFormat.HLS);
    } else {
      throw new IllegalArgumentException("Unsupported stream format:" + format);
    }
    // Optional params.
    @Nullable String adTagParametersValue = uri.getQueryParameter(AD_TAG_PARAMETERS);
    if (!TextUtils.isEmpty(adTagParametersValue)) {
      Map<String, String> adTagParameters = new HashMap<>();
      Uri adTagParametersUri = Uri.parse(adTagParametersValue);
      for (String paramName : adTagParametersUri.getQueryParameterNames()) {
        String singleAdTagParameterValue = adTagParametersUri.getQueryParameter(paramName);
        if (!TextUtils.isEmpty(singleAdTagParameterValue)) {
          adTagParameters.put(paramName, singleAdTagParameterValue);
        }
      }
      streamRequest.setAdTagParameters(adTagParameters);
    }
    @Nullable String manifestSuffix = uri.getQueryParameter(MANIFEST_SUFFIX);
    if (manifestSuffix != null) {
      streamRequest.setManifestSuffix(manifestSuffix);
    }

View on GitHub (pinned to dd430f7053)

Solutions

  1. Build the URI with ImaServerSideAdInsertionUriBuilder and pass setFormat(C.CONTENT_TYPE_DASH) or setFormat(C.CONTENT_TYPE_HLS).
  2. If URIs come from a server/deep link, validate the format parameter at ingestion and reject/normalize values outside {DASH, HLS} before playback.
  3. Ensure the URI retains the FORMAT query parameter after any URL encoding/rewriting step.

Example fix

// before
Uri uri = Uri.parse("imasky://ima?asset_key=...&format=1"); // IllegalArgumentException: Unsupported stream format:1

// after
Uri uri = new ImaServerSideAdInsertionUriBuilder()
    .setAssetKey("...")
    .setFormat(C.CONTENT_TYPE_DASH) // or C.CONTENT_TYPE_HLS
    .build();
Defensive patterns

Strategy: validation

Validate before calling

@Nullable String f = uri.getQueryParameter("format");
boolean supported = false;
try { int fmt = Integer.parseInt(f); supported = fmt == C.CONTENT_TYPE_DASH || fmt == C.CONTENT_TYPE_HLS; }
catch (NumberFormatException ignored) {}
if (!supported) throw new IllegalArgumentException("Bad format");

Try / catch

catch (IllegalArgumentException e) { if (e.getMessage() != null && e.getMessage().startsWith("Unsupported stream format")) normalizeFormatAndRebuild(); }

Prevention

When it happens

Trigger: A URI with format=2 (CONTENT_TYPE_OTHER), format=1, a missing-but-defaulted value, or a typo like format=dash (Integer.parseInt throws NumberFormatException before this check) reaching createStreamRequest. Usually results from manual URI construction or a stale/cached URI built against different constants.

Common situations: Hand-writing the imasky:// URI and guessing the format code; copying example URIs with format=1; a backend delivering deep links with an unset or unsupported format parameter; format constant changes between ExoPlayer versions.

Related errors


AI-assisted analysis of google/ExoPlayer@dd430f7053 (2026-08-14). Data as JSON: /api/errors/17e6076f9c4c2a69. Report an issue: GitHub.