mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Prevent adding multiple IMA SSAI media source instances to the playlist
Currently only a single instance of ImaServerSideAdInsertionMediaSource is supported at the same time in a playlist. This change makes sure that an attempt to add multiple instances is prevented by throwing a an exception. #minor-release PiperOrigin-RevId: 428743140
This commit is contained in:
parent
940e934b58
commit
de3708ee12
2 changed files with 18 additions and 1 deletions
|
|
@ -377,6 +377,7 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void prepareSourceInternal(@Nullable TransferListener mediaTransferListener) {
|
public void prepareSourceInternal(@Nullable TransferListener mediaTransferListener) {
|
||||||
|
mainHandler.post(() -> assertSingleInstanceInPlaylist(checkNotNull(player)));
|
||||||
super.prepareSourceInternal(mediaTransferListener);
|
super.prepareSourceInternal(mediaTransferListener);
|
||||||
if (loader == null) {
|
if (loader == null) {
|
||||||
Loader loader = new Loader("ImaServerSideAdInsertionMediaSource");
|
Loader loader = new Loader("ImaServerSideAdInsertionMediaSource");
|
||||||
|
|
@ -1150,4 +1151,20 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
|
||||||
overlayInfo.reasonDetail != null ? overlayInfo.reasonDetail : "Unknown reason"));
|
overlayInfo.reasonDetail != null ? overlayInfo.reasonDetail : "Unknown reason"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void assertSingleInstanceInPlaylist(Player player) {
|
||||||
|
int counter = 0;
|
||||||
|
for (int i = 0; i < player.getMediaItemCount(); i++) {
|
||||||
|
MediaItem mediaItem = player.getMediaItemAt(i);
|
||||||
|
if (mediaItem.localConfiguration != null
|
||||||
|
&& C.SSAI_SCHEME.equals(mediaItem.localConfiguration.uri.getScheme())
|
||||||
|
&& ImaServerSideAdInsertionUriBuilder.IMA_AUTHORITY.equals(
|
||||||
|
mediaItem.localConfiguration.uri.getAuthority())) {
|
||||||
|
if (++counter > 1) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Multiple IMA server side ad insertion sources not supported.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ public final class ImaServerSideAdInsertionUriBuilder {
|
||||||
/** The default timeout for loading the video URI, in milliseconds. */
|
/** The default timeout for loading the video URI, in milliseconds. */
|
||||||
public static final int DEFAULT_LOAD_VIDEO_TIMEOUT_MS = 10_000;
|
public static final int DEFAULT_LOAD_VIDEO_TIMEOUT_MS = 10_000;
|
||||||
|
|
||||||
private static final String IMA_AUTHORITY = "dai.google.com";
|
/* package */ static final String IMA_AUTHORITY = "dai.google.com";
|
||||||
private static final String ADS_ID = "adsId";
|
private static final String ADS_ID = "adsId";
|
||||||
private static final String ASSET_KEY = "assetKey";
|
private static final String ASSET_KEY = "assetKey";
|
||||||
private static final String API_KEY = "apiKey";
|
private static final String API_KEY = "apiKey";
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue