Allow setting supported formats on AdsLoaders
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=177175377
This commit is contained in:
parent
ff49bc97c4
commit
2282527821
@ -26,9 +26,9 @@ import java.util.List;
|
||||
*/
|
||||
/* package */ final class DemoUtil {
|
||||
|
||||
public static final String MIME_TYPE_DASH = "application/dash+xml";
|
||||
public static final String MIME_TYPE_HLS = "application/vnd.apple.mpegurl";
|
||||
public static final String MIME_TYPE_SS = "application/vnd.ms-sstr+xml";
|
||||
public static final String MIME_TYPE_DASH = MimeTypes.APPLICATION_MPD;
|
||||
public static final String MIME_TYPE_HLS = MimeTypes.APPLICATION_M3U8;
|
||||
public static final String MIME_TYPE_SS = MimeTypes.APPLICATION_SS;
|
||||
public static final String MIME_TYPE_VIDEO_MP4 = MimeTypes.VIDEO_MP4;
|
||||
|
||||
/**
|
||||
|
@ -49,10 +49,13 @@ import com.google.android.exoplayer2.Timeline;
|
||||
import com.google.android.exoplayer2.source.ads.AdPlaybackState;
|
||||
import com.google.android.exoplayer2.source.ads.AdsLoader;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -117,6 +120,7 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A
|
||||
private final AdDisplayContainer adDisplayContainer;
|
||||
private final com.google.ads.interactivemedia.v3.api.AdsLoader adsLoader;
|
||||
|
||||
private List<String> supportedMimeTypes;
|
||||
private EventListener eventListener;
|
||||
private Player player;
|
||||
private ViewGroup adUiViewGroup;
|
||||
@ -238,6 +242,25 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A
|
||||
|
||||
// AdsLoader implementation.
|
||||
|
||||
@Override
|
||||
public void setSupportedContentTypes(@C.ContentType int... contentTypes) {
|
||||
List<String> supportedMimeTypes = new ArrayList<>();
|
||||
for (@C.ContentType int contentType : contentTypes) {
|
||||
if (contentType == C.TYPE_DASH) {
|
||||
supportedMimeTypes.add(MimeTypes.APPLICATION_MPD);
|
||||
} else if (contentType == C.TYPE_HLS) {
|
||||
supportedMimeTypes.add(MimeTypes.APPLICATION_M3U8);
|
||||
} else if (contentType == C.TYPE_OTHER) {
|
||||
supportedMimeTypes.addAll(Arrays.asList(
|
||||
MimeTypes.VIDEO_MP4, MimeTypes.VIDEO_WEBM, MimeTypes.VIDEO_H263, MimeTypes.VIDEO_MPEG,
|
||||
MimeTypes.AUDIO_MP4, MimeTypes.AUDIO_MPEG));
|
||||
} else if (contentType == C.TYPE_SS) {
|
||||
// IMA does not support SmoothStreaming ad media.
|
||||
}
|
||||
}
|
||||
this.supportedMimeTypes = Collections.unmodifiableList(supportedMimeTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachPlayer(ExoPlayer player, EventListener eventListener, ViewGroup adUiViewGroup) {
|
||||
this.player = player;
|
||||
@ -296,6 +319,7 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A
|
||||
ImaSdkFactory imaSdkFactory = ImaSdkFactory.getInstance();
|
||||
AdsRenderingSettings adsRenderingSettings = imaSdkFactory.createAdsRenderingSettings();
|
||||
adsRenderingSettings.setEnablePreloading(true);
|
||||
adsRenderingSettings.setMimeTypes(supportedMimeTypes);
|
||||
adsManager.init(adsRenderingSettings);
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Initialized with preloading");
|
||||
|
@ -16,6 +16,7 @@
|
||||
package com.google.android.exoplayer2.source.ads;
|
||||
|
||||
import android.view.ViewGroup;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
import java.io.IOException;
|
||||
|
||||
@ -71,6 +72,15 @@ public interface AdsLoader {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the supported content types for ad media. Must be called before the first call to
|
||||
* {@link #attachPlayer(ExoPlayer, EventListener, ViewGroup)}. Subsequent calls may be ignored.
|
||||
*
|
||||
* @param contentTypes The supported content types for ad media. Each element must be one of
|
||||
* {@link C#TYPE_DASH}, {@link C#TYPE_HLS}, {@link C#TYPE_SS} and {@link C#TYPE_OTHER}.
|
||||
*/
|
||||
void setSupportedContentTypes(@C.ContentType int... contentTypes);
|
||||
|
||||
/**
|
||||
* Attaches a player that will play ads loaded using this instance. Called on the main thread by
|
||||
* {@link AdsMediaSource}.
|
||||
|
@ -132,6 +132,7 @@ public final class AdsMediaSource implements MediaSource {
|
||||
period = new Timeline.Period();
|
||||
adGroupMediaSources = new MediaSource[0][];
|
||||
adDurationsUs = new long[0][];
|
||||
adsLoader.setSupportedContentTypes(C.TYPE_OTHER);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,6 +36,7 @@ public final class MimeTypes {
|
||||
public static final String VIDEO_VP8 = BASE_TYPE_VIDEO + "/x-vnd.on2.vp8";
|
||||
public static final String VIDEO_VP9 = BASE_TYPE_VIDEO + "/x-vnd.on2.vp9";
|
||||
public static final String VIDEO_MP4V = BASE_TYPE_VIDEO + "/mp4v-es";
|
||||
public static final String VIDEO_MPEG = BASE_TYPE_VIDEO + "/mpeg";
|
||||
public static final String VIDEO_MPEG2 = BASE_TYPE_VIDEO + "/mpeg2";
|
||||
public static final String VIDEO_VC1 = BASE_TYPE_VIDEO + "/wvc1";
|
||||
public static final String VIDEO_UNKNOWN = BASE_TYPE_VIDEO + "/x-unknown";
|
||||
@ -70,7 +71,9 @@ public final class MimeTypes {
|
||||
|
||||
public static final String APPLICATION_MP4 = BASE_TYPE_APPLICATION + "/mp4";
|
||||
public static final String APPLICATION_WEBM = BASE_TYPE_APPLICATION + "/webm";
|
||||
public static final String APPLICATION_MPD = BASE_TYPE_APPLICATION + "/dash+xml";
|
||||
public static final String APPLICATION_M3U8 = BASE_TYPE_APPLICATION + "/x-mpegURL";
|
||||
public static final String APPLICATION_SS = BASE_TYPE_APPLICATION + "/vnd.ms-sstr+xml";
|
||||
public static final String APPLICATION_ID3 = BASE_TYPE_APPLICATION + "/id3";
|
||||
public static final String APPLICATION_CEA608 = BASE_TYPE_APPLICATION + "/cea-608";
|
||||
public static final String APPLICATION_CEA708 = BASE_TYPE_APPLICATION + "/cea-708";
|
||||
|
@ -905,8 +905,7 @@ public final class DashMediaSource implements MediaSource {
|
||||
|
||||
}
|
||||
|
||||
private final class ManifestCallback implements
|
||||
Loader.Callback<ParsingLoadable<DashManifest>> {
|
||||
private final class ManifestCallback implements Loader.Callback<ParsingLoadable<DashManifest>> {
|
||||
|
||||
@Override
|
||||
public void onLoadCompleted(ParsingLoadable<DashManifest> loadable,
|
||||
|
Loading…
x
Reference in New Issue
Block a user