mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Redefine the SSAI URI format with an "ssai" scheme instead of "imadai"
This allows us to remove the IMA naming from DefaultMediaSourceFactory's SSAI integration. #minor-release PiperOrigin-RevId: 426346456
This commit is contained in:
parent
e2d4bd15cd
commit
dc6bf507c7
@ -29,6 +29,7 @@ import android.media.AudioManager;
|
||||
import android.media.MediaCodec;
|
||||
import android.media.MediaCrypto;
|
||||
import android.media.MediaFormat;
|
||||
import android.net.Uri;
|
||||
import android.view.Surface;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.RequiresApi;
|
||||
@ -125,6 +126,9 @@ public final class C {
|
||||
/** The name of the sans-serif font family. */
|
||||
@UnstableApi public static final String SANS_SERIF_NAME = "sans-serif";
|
||||
|
||||
/** The {@link Uri#getScheme() URI scheme} used for content with server side ad insertion. */
|
||||
@UnstableApi public static final String SSAI_SCHEME = "ssai";
|
||||
|
||||
/**
|
||||
* Types of crypto implementation. May be one of {@link #CRYPTO_TYPE_NONE}, {@link
|
||||
* #CRYPTO_TYPE_UNSUPPORTED} or {@link #CRYPTO_TYPE_FRAMEWORK}. May also be an app-defined value
|
||||
|
@ -20,6 +20,7 @@ import static androidx.media3.common.util.Assertions.checkStateNotNull;
|
||||
import static androidx.media3.common.util.Util.castNonNull;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.AdViewProvider;
|
||||
import androidx.media3.common.C;
|
||||
@ -106,7 +107,7 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
|
||||
private final DataSource.Factory dataSourceFactory;
|
||||
private final DelegateFactoryLoader delegateFactoryLoader;
|
||||
|
||||
@Nullable private MediaSource.Factory imaServerSideAdInsertionMediaSourceFactory;
|
||||
@Nullable private MediaSource.Factory serverSideAdInsertionMediaSourceFactory;
|
||||
@Nullable private AdsLoader.Provider adsLoaderProvider;
|
||||
@Nullable private AdViewProvider adViewProvider;
|
||||
@Nullable private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
|
||||
@ -212,22 +213,19 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link MediaSource.Factory} used to handle {@link MediaItem} instances containing <a
|
||||
* href="https://support.google.com/admanager/answer/6147120">IMA Dynamic Ad Insertion URIs</a>.
|
||||
* Sets the {@link MediaSource.Factory} used to handle {@link MediaItem} instances containing a
|
||||
* {@link Uri} identified as resolving to content with server side ad insertion (SSAI).
|
||||
*
|
||||
* <p>In most cases this will be an {@code ImaServerSideAdInsertionMediaSource.Factory} from the
|
||||
* IMA extension.
|
||||
* <p>SSAI URIs are those with a {@link Uri#getScheme() scheme} of {@link C#SSAI_SCHEME}.
|
||||
*
|
||||
* <p>IMA DAI URIs are those with a scheme of {@code "imadai"}.
|
||||
*
|
||||
* @param imaServerSideAdInsertionMediaSourceFactory The {@link MediaSource.Factory} for IMA DAI
|
||||
* @param serverSideAdInsertionMediaSourceFactory The {@link MediaSource.Factory} for SSAI
|
||||
* content, or {@code null} to remove a previously set {@link MediaSource.Factory}.
|
||||
* @return This factory, for convenience.
|
||||
*/
|
||||
@UnstableApi
|
||||
public DefaultMediaSourceFactory setImaServerSideAdInsertionMediaSourceFactory(
|
||||
@Nullable MediaSource.Factory imaServerSideAdInsertionMediaSourceFactory) {
|
||||
this.imaServerSideAdInsertionMediaSourceFactory = imaServerSideAdInsertionMediaSourceFactory;
|
||||
public DefaultMediaSourceFactory setServerSideAdInsertionMediaSourceFactory(
|
||||
@Nullable MediaSource.Factory serverSideAdInsertionMediaSourceFactory) {
|
||||
this.serverSideAdInsertionMediaSourceFactory = serverSideAdInsertionMediaSourceFactory;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -324,8 +322,8 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
|
||||
public MediaSource createMediaSource(MediaItem mediaItem) {
|
||||
Assertions.checkNotNull(mediaItem.localConfiguration);
|
||||
@Nullable String scheme = mediaItem.localConfiguration.uri.getScheme();
|
||||
if (scheme != null && scheme.equals("imadai")) {
|
||||
return checkNotNull(imaServerSideAdInsertionMediaSourceFactory).createMediaSource(mediaItem);
|
||||
if (scheme != null && scheme.equals(C.SSAI_SCHEME)) {
|
||||
return checkNotNull(serverSideAdInsertionMediaSourceFactory).createMediaSource(mediaItem);
|
||||
}
|
||||
@C.ContentType
|
||||
int type =
|
||||
|
@ -246,7 +246,7 @@ import java.util.Map;
|
||||
}
|
||||
}
|
||||
|
||||
private static final String SCHEME = "imadai";
|
||||
private static final String IMA_AUTHORITY = "dai.google.com";
|
||||
private static final String ADS_ID = "adsId";
|
||||
private static final String ASSET_KEY = "assetKey";
|
||||
private static final String API_KEY = "apiKey";
|
||||
@ -341,7 +341,8 @@ import java.util.Map;
|
||||
/** Returns a corresponding {@link Uri}. */
|
||||
public Uri toUri() {
|
||||
Uri.Builder dataUriBuilder = new Uri.Builder();
|
||||
dataUriBuilder.scheme(SCHEME);
|
||||
dataUriBuilder.scheme(C.SSAI_SCHEME);
|
||||
dataUriBuilder.authority(IMA_AUTHORITY);
|
||||
dataUriBuilder.appendQueryParameter(ADS_ID, adsId);
|
||||
if (loadVideoTimeoutMs != DEFAULT_LOAD_VIDEO_TIMEOUT_MS) {
|
||||
dataUriBuilder.appendQueryParameter(
|
||||
@ -433,8 +434,8 @@ import java.util.Map;
|
||||
public static ServerSideAdInsertionStreamRequest fromUri(Uri uri) {
|
||||
ServerSideAdInsertionStreamRequest.Builder request =
|
||||
new ServerSideAdInsertionStreamRequest.Builder();
|
||||
if (!SCHEME.equals(uri.getScheme())) {
|
||||
throw new IllegalArgumentException("Invalid scheme.");
|
||||
if (!C.SSAI_SCHEME.equals(uri.getScheme()) || !IMA_AUTHORITY.equals(uri.getAuthority())) {
|
||||
throw new IllegalArgumentException("Invalid URI scheme or authority.");
|
||||
}
|
||||
request.setAdsId(checkNotNull(uri.getQueryParameter(ADS_ID)));
|
||||
request.setAssetKey(uri.getQueryParameter(ASSET_KEY));
|
||||
|
Loading…
x
Reference in New Issue
Block a user