com.google.ads.interactivemedia.v3.api.ImaSdkFactory Java Examples

The following examples show how to use com.google.ads.interactivemedia.v3.api.ImaSdkFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AdController.java    From xipl with Apache License 2.0 5 votes vote down vote up
public AdController(Context context) {
    // Create an AdsLoader.
    mSdkFactory = ImaSdkFactory.getInstance();
    mAdsLoader = mSdkFactory.createAdsLoader(context);
    mAdsLoader.addAdErrorListener(this);
    mAdsLoader.addAdsLoadedListener(this);

    mStubViewGroup = new FrameLayout(context);
}
 
Example #2
Source File: AdController.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
public AdController(Context context) {
    // Create an AdsLoader.
    mSdkFactory = ImaSdkFactory.getInstance();
    mAdsLoader = mSdkFactory.createAdsLoader(context);
    mAdsLoader.addAdErrorListener(this);
    mAdsLoader.addAdsLoadedListener(this);

    mStubViewGroup = new FrameLayout(context);
}
 
Example #3
Source File: ImaPlayer.java    From google-media-framework-android with Apache License 2.0 5 votes vote down vote up
/**
 * @param activity The activity that will contain the video player.
 * @param container The {@link FrameLayout} which will contain the video player.
 * @param video The video that should be played.
 * @param videoTitle The title of the video (displayed on the left of the top chrome).
 * @param adTagUrl The URL containing the VAST document of the ad.
 */
public ImaPlayer(Activity activity,
                 FrameLayout container,
                 Video video,
                 String videoTitle,
                 String adTagUrl) {
  this(activity,
      container,
      video,
      videoTitle,
      ImaSdkFactory.getInstance().createImaSdkSettings(),
      adTagUrl);
}
 
Example #4
Source File: ImaPlayer.java    From google-media-framework-android with Apache License 2.0 5 votes vote down vote up
/**
 * @param activity The activity that will contain the video player.
 * @param container The {@link FrameLayout} which will contain the video player.
 * @param video The video that should be played.
 * @param videoTitle The title of the video (displayed on the left of the top chrome).
 */
public ImaPlayer(Activity activity,
                 FrameLayout container,
                 Video video,
                 String videoTitle) {
  this(activity,
      container,
      video,
      videoTitle,
      ImaSdkFactory.getInstance().createImaSdkSettings(),
      null);
}
 
Example #5
Source File: ImaPlayer.java    From google-media-framework-android with Apache License 2.0 5 votes vote down vote up
/**
 * @param activity The activity that will contain the video player.
 * @param container The {@link FrameLayout} which will contain the video player.
 * @param video The video that should be played.
 */
public ImaPlayer(Activity activity,
                 FrameLayout container,
                 Video video) {
  this(activity,
      container,
      video,
      "",
      ImaSdkFactory.getInstance().createImaSdkSettings(),
      null);
}
 
Example #6
Source File: ImaPlayer.java    From google-media-framework-android with Apache License 2.0 5 votes vote down vote up
/**
 * Create an ads request which will request the VAST document with the given ad tag URL.
 * @param tagUrl URL pointing to a VAST document of an ad.
 * @return a request for the VAST document.
 */
private AdsRequest buildAdsRequest(String tagUrl) {
  AdDisplayContainer adDisplayContainer = ImaSdkFactory.getInstance().createAdDisplayContainer();
  adDisplayContainer.setPlayer(videoAdPlayer);
  adDisplayContainer.setAdContainer(adUiContainer);
  AdsRequest request = ImaSdkFactory.getInstance().createAdsRequest();
  request.setAdTagUrl(tagUrl);
  request.setContentProgressProvider(contentProgressProvider);

  request.setAdDisplayContainer(adDisplayContainer);
  return request;
}
 
Example #7
Source File: AudioPlayerService.java    From googleads-ima-android with Apache License 2.0 5 votes vote down vote up
public void initializeAds(Context context, ViewGroup companionView) {
  ImaSdkFactory sdkFactory = ImaSdkFactory.getInstance();
  AdDisplayContainer container =
      ImaSdkFactory.createAudioAdDisplayContainer(context, imaService.imaVideoAdPlayer);
  CompanionAdSlot companionAdSlot = sdkFactory.createCompanionAdSlot();
  companionAdSlot.setContainer(companionView);
  companionAdSlot.setSize(300, 250);
  container.setCompanionSlots(ImmutableList.of(companionAdSlot));
  imaService.init(container);
}
 
Example #8
Source File: ImaService.java    From googleads-ima-android with Apache License 2.0 5 votes vote down vote up
ImaService(
    Context context,
    DefaultDataSourceFactory dataSourceFactory,
    AudioPlayerService.SharedAudioPlayer sharedAudioPlayer) {
  this.context = context;
  this.sharedAudioPlayer = sharedAudioPlayer;
  this.exoPlayer = sharedAudioPlayer.getPlayer();
  this.callbacks = new ArrayList<>();
  this.sdkFactory = ImaSdkFactory.getInstance();
  this.imaSdkSettings = ImaSdkFactory.getInstance().createImaSdkSettings();
  this.dataSourceFactory = dataSourceFactory;
  sharedAudioPlayer.addAnalyticsListener(new ImaListener());
}
 
Example #9
Source File: ImaPlayer.java    From google-media-framework-android with Apache License 2.0 4 votes vote down vote up
/**
 * @param activity The activity that will contain the video player.
 * @param container The {@link FrameLayout} which will contain the video player.
 * @param video The video that should be played.
 * @param videoTitle The title of the video (displayed on the left of the top chrome).
 * @param sdkSettings The settings that should be used to configure the IMA SDK.
 * @param adTagUrl The URL containing the VAST document of the ad.
 * @param fullscreenCallback The callback that should be triggered when the player enters or
 *                           leaves fullscreen.
 */
public ImaPlayer(Activity activity,
                 FrameLayout container,
                 Video video,
                 String videoTitle,
                 ImaSdkSettings sdkSettings,
                 String adTagUrl,
                 PlaybackControlLayer.FullscreenCallback fullscreenCallback) {
  this.activity = activity;
  this.container = container;

  if (adTagUrl != null) {
    this.adTagUrl = Uri.parse(adTagUrl);
  }

  sdkSettings.setPlayerType(PLAYER_TYPE);
  sdkSettings.setPlayerVersion(PLAYER_VERSION);
  adsLoader = ImaSdkFactory.getInstance().createAdsLoader(activity, sdkSettings);
  adListener = new AdListener();
  adsLoader.addAdErrorListener(adListener);
  adsLoader.addAdsLoadedListener(adListener);

  callbacks = new ArrayList<VideoAdPlayer.VideoAdPlayerCallback>();

  boolean autoplay = false;
  contentPlayer = new SimpleVideoPlayer(activity,
      container,
      video,
      videoTitle,
      autoplay);

  contentPlayer.addPlaybackListener(contentPlaybackListener);

  // Move the content player's surface layer to the background so that the ad player's surface
  // layer can be overlaid on top of it during ad playback.
  contentPlayer.moveSurfaceToBackground();
  contentPlayer.hide();

  // Create the ad adDisplayContainer UI which will be used by the IMA SDK to overlay ad controls.
  adUiContainer = new FrameLayout(activity);
  container.addView(adUiContainer);
  adUiContainer.setLayoutParams(Util.getLayoutParamsBasedOnParent(
      adUiContainer,
      ViewGroup.LayoutParams.MATCH_PARENT,
      ViewGroup.LayoutParams.MATCH_PARENT));


  this.originalContainerLayoutParams = container.getLayoutParams();

  setFullscreenCallback(fullscreenCallback);
}
 
Example #10
Source File: VideoPlayerController.java    From googleads-ima-android with Apache License 2.0 4 votes vote down vote up
/** An event raised when ads are successfully loaded from the ad server via AdsLoader. */
@Override
public void onAdsManagerLoaded(AdsManagerLoadedEvent adsManagerLoadedEvent) {
  // Ads were successfully loaded, so get the AdsManager instance. AdsManager has
  // events for ad playback and errors.
  mAdsManager = adsManagerLoadedEvent.getAdsManager();

  // Attach event and error event listeners.
  mAdsManager.addAdErrorListener(
      new AdErrorEvent.AdErrorListener() {
        /** An event raised when there is an error loading or playing ads. */
        @Override
        public void onAdError(AdErrorEvent adErrorEvent) {
          log("Ad Error: " + adErrorEvent.getError().getMessage());
          resumeContent();
        }
      });
  mAdsManager.addAdEventListener(
      new AdEvent.AdEventListener() {
        /** Responds to AdEvents. */
        @Override
        public void onAdEvent(AdEvent adEvent) {
          log("Event: " + adEvent.getType());

          // These are the suggested event types to handle. For full list of all ad
          // event types, see the documentation for AdEvent.AdEventType.
          switch (adEvent.getType()) {
            case LOADED:
              // AdEventType.LOADED will be fired when ads are ready to be
              // played. AdsManager.start() begins ad playback. This method is
              // ignored for VMAP or ad rules playlists, as the SDK will
              // automatically start executing the playlist.
              mAdsManager.start();
              break;
            case CONTENT_PAUSE_REQUESTED:
              // AdEventType.CONTENT_PAUSE_REQUESTED is fired immediately before
              // a video ad is played.
              pauseContent();
              break;
            case CONTENT_RESUME_REQUESTED:
              // AdEventType.CONTENT_RESUME_REQUESTED is fired when the ad is
              // completed and you should start playing your content.
              resumeContent();
              break;
            case PAUSED:
              mIsAdPlaying = false;
              break;
            case RESUMED:
              mIsAdPlaying = true;
              break;
            case ALL_ADS_COMPLETED:
              if (mAdsManager != null) {
                mAdsManager.destroy();
                mAdsManager = null;
              }
              break;
            default:
              break;
          }
        }
      });
  AdsRenderingSettings adsRenderingSettings =
      ImaSdkFactory.getInstance().createAdsRenderingSettings();
  adsRenderingSettings.setPlayAdsAfterTime(mPlayAdsAfterTime);
  mAdsManager.init(adsRenderingSettings);
  seek(mPlayAdsAfterTime);
  mVideoStarted = true;
}
 
Example #11
Source File: VideoPlayerController.java    From googleads-ima-android with Apache License 2.0 4 votes vote down vote up
public VideoPlayerController(
    Context context,
    VideoPlayerWithAdPlayback videoPlayerWithAdPlayback,
    View playButton,
    View playPauseToggle,
    String language,
    ViewGroup companionViewGroup,
    Logger log) {
  mVideoPlayerWithAdPlayback = videoPlayerWithAdPlayback;
  mPlayButton = playButton;
  mPlayPauseToggle = playPauseToggle;
  mIsAdPlaying = false;
  mCompanionViewGroup = companionViewGroup;
  mLog = log;

  // Create an AdsLoader and optionally set the language.
  mSdkFactory = ImaSdkFactory.getInstance();
  ImaSdkSettings imaSdkSettings = mSdkFactory.createImaSdkSettings();
  imaSdkSettings.setLanguage(language);

  mAdDisplayContainer =
      ImaSdkFactory.createAdDisplayContainer(
          mVideoPlayerWithAdPlayback.getAdUiContainer(),
          mVideoPlayerWithAdPlayback.getVideoAdPlayer());
  mAdsLoader = mSdkFactory.createAdsLoader(context, imaSdkSettings, mAdDisplayContainer);

  mAdsLoader.addAdErrorListener(
      new AdErrorEvent.AdErrorListener() {
        /** An event raised when there is an error loading or playing ads. */
        @Override
        public void onAdError(AdErrorEvent adErrorEvent) {
          log("Ad Error: " + adErrorEvent.getError().getMessage());
          resumeContent();
        }
      });

  mAdsLoader.addAdsLoadedListener(new VideoPlayerController.AdsLoadedListener());

  // When Play is clicked, request ads and hide the button.
  mPlayButton.setOnClickListener(
      new View.OnClickListener() {
        @Override
        public void onClick(View view) {
          requestAndPlayAds(-1);
        }
      });
}