google/ExoPlayer · error · IllegalArgumentException
Invalid URI scheme or authority.
Error message
Invalid URI scheme or authority.
What it means
Thrown by ImaServerSideAdInsertionUriBuilder.createStreamRequest when the URI passed in does not have both the expected SSAI scheme (imasky via C.SSAI_SCHEME) and the IMA authority. These URIs are synthetic identifiers that only exist to carry DAI stream parameters from your app into the ImaServerSideAdInsertionMediaSource; anything else reaching this method is a programming error.
Source
Thrown at extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/ImaServerSideAdInsertionUriBuilder.java:336
/** Returns the opaque adsId for this stream. */
/* package */ static String getAdsId(Uri uri) {
return checkNotNull(uri.getQueryParameter(ADS_ID));
}
/** Returns the video load timeout in milliseconds. */
/* package */ static int getLoadVideoTimeoutMs(Uri uri) {
@Nullable String adsLoaderTimeoutUs = uri.getQueryParameter(LOAD_VIDEO_TIMEOUT_MS);
return TextUtils.isEmpty(adsLoaderTimeoutUs)
? DEFAULT_LOAD_VIDEO_TIMEOUT_MS
: Integer.parseInt(adsLoaderTimeoutUs);
}
/** Returns the corresponding {@link StreamRequest}. */
@SuppressWarnings("nullness") // Required for making nullness test pass for library_with_ima_sdk.
/* package */ static StreamRequest createStreamRequest(Uri uri) {
if (!C.SSAI_SCHEME.equals(uri.getScheme()) || !IMA_AUTHORITY.equals(uri.getAuthority())) {
throw new IllegalArgumentException("Invalid URI scheme or authority.");
}
StreamRequest streamRequest;
// 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) {View on GitHub (pinned to dd430f7053)
Solutions
- Always construct the URI with ImaServerSideAdInsertionUriBuilder.build() rather than string concatenation — it emits the correct scheme/authority by construction.
- If you must inspect URIs, gate routing on C.SSAI_SCHEME.equals(uri.getScheme()) && IMA_AUTHORITY.equals(uri.getAuthority()) before passing to the SSAI source.
- Log the offending URI at the point of failure to find which code path produced the malformed value.
Example fix
// before
Uri uri = Uri.parse("imsky://ima/?asset_key=..."); // typo'd scheme -> IllegalArgumentException
// after
Uri uri = new ImaServerSideAdInsertionUriBuilder()
.setAssetKey("...")
.setFormat(C.CONTENT_TYPE_HLS)
.build(); Defensive patterns
Strategy: type-guard
Validate before calling
boolean isSsaiUri(Uri uri) {
return C.SSAI_SCHEME.equals(uri.getScheme())
&& ImaServerSideAdInsertionUriBuilder.IMA_AUTHORITY.equals(uri.getAuthority());
} Type guard
static boolean isImaSsaiUri(@Nullable Uri uri) {
return uri != null
&& C.SSAI_SCHEME.equals(uri.getScheme())
&& "ima".equals(uri.getAuthority());
} Try / catch
catch (IllegalArgumentException e) { if ("Invalid URI scheme or authority.".equals(e.getMessage())) { rejectItem(); } else throw e; } Prevention
- Always construct SSAI URIs via ImaServerSideAdInsertionUriBuilder — never string concatenation.
- Route media items by scheme/authority before handing them to the SSAI MediaSource.
When it happens
Trigger: Calling createStreamRequest with a URI whose getScheme() != C.SSAI_SCHEME or getAuthority() != IMA_AUTHORITY — typically because the URI was hand-concatenated (e.g. "imasky://" misspelled), parsed from a string that lost its scheme, or an unrelated content URI was routed to the SSAI media source.
Common situations: Building the SSAI URI manually with String concatenation instead of ImaServerSideAdInsertionUriBuilder; Uri.parse on a malformed string returning a Uri with null scheme/authority; a custom MediaSourceFactory delegating all items to the SSAI source without a scheme check.
Related errors
- Multiple IMA server side ad insertion sources not supported.
- Unsupported stream format:${format}
- ${errorMessage} [errorCode: ${errorCode}]
- No unplayed ad group found before or at the start time us %d
- Unexpected color filter ${colorFilterSelection}
AI-assisted analysis of google/ExoPlayer@dd430f7053 (2026-08-14).
Data as JSON: /api/errors/cf2a54ce500eb606.
Report an issue: GitHub.