com.google.ads.interactivemedia.v3.api.player.VideoAdPlayer Java Examples

The following examples show how to use com.google.ads.interactivemedia.v3.api.player.VideoAdPlayer. 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: ImaPlayer.java    From google-media-framework-android with Apache License 2.0 5 votes vote down vote up
/**
 * We notify all callbacks when the ad ends.
 * @param playWhenReady Whether the video should play as soon as it is loaded.
 * @param playbackState The state of the Exoplayer instance.
 */
@Override
public void onStateChanged(boolean playWhenReady, int playbackState) {
  if (playbackState == ExoPlayer.STATE_ENDED) {
    for (VideoAdPlayer.VideoAdPlayerCallback callback : callbacks) {
      callback.onEnded();
    }
  }
}
 
Example #2
Source File: ImaPlayer.java    From google-media-framework-android with Apache License 2.0 5 votes vote down vote up
/**
 * Pause the content player and notify the ad callbacks that the content has paused.
 */
private void pauseContent(){
  hideContentPlayer();
  for (VideoAdPlayer.VideoAdPlayerCallback callback : callbacks) {
    callback.onPause();
  }
}
 
Example #3
Source File: ImaPlayer.java    From google-media-framework-android with Apache License 2.0 5 votes vote down vote up
/**
 * Resume the content and notify the ad callbacks that the content has resumed.
 */
private void resumeContent(){
  destroyAdPlayer();
  showContentPlayer();
  for (VideoAdPlayer.VideoAdPlayerCallback callback : callbacks) {
    callback.onResume();
  }
}
 
Example #4
Source File: AdController.java    From xipl with Apache License 2.0 4 votes vote down vote up
@Override
public void addCallback(VideoAdPlayer.VideoAdPlayerCallback videoAdPlayerCallback) {
    mAdCallbacks.add(videoAdPlayerCallback);
}
 
Example #5
Source File: AdController.java    From xipl with Apache License 2.0 4 votes vote down vote up
@Override
public void removeCallback(VideoAdPlayer.VideoAdPlayerCallback videoAdPlayerCallback) {
    mAdCallbacks.remove(videoAdPlayerCallback);
}
 
Example #6
Source File: AdController.java    From androidtv-sample-inputs with Apache License 2.0 4 votes vote down vote up
@Override
public void addCallback(VideoAdPlayer.VideoAdPlayerCallback videoAdPlayerCallback) {
    mAdCallbacks.add(videoAdPlayerCallback);
}
 
Example #7
Source File: AdController.java    From androidtv-sample-inputs with Apache License 2.0 4 votes vote down vote up
@Override
public void removeCallback(VideoAdPlayer.VideoAdPlayerCallback videoAdPlayerCallback) {
    mAdCallbacks.remove(videoAdPlayerCallback);
}
 
Example #8
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 #9
Source File: ImaPlayer.java    From google-media-framework-android with Apache License 2.0 4 votes vote down vote up
/**
 * Create a {@link SimpleVideoPlayer} to play an ad and display it.
 */
private void createAdPlayer(){
  // Kill any existing ad player.
  destroyAdPlayer();

  // Add the ad frame layout to the adDisplayContainer that contains all the content player.
  adPlayerContainer = new FrameLayout(activity);
  container.addView(adPlayerContainer);
  adPlayerContainer.setLayoutParams(Util.getLayoutParamsBasedOnParent(
      adPlayerContainer,
      ViewGroup.LayoutParams.MATCH_PARENT,
      ViewGroup.LayoutParams.MATCH_PARENT
  ));

  // Ensure tha the ad ui adDisplayContainer is the topmost view.
  container.removeView(adUiContainer);
  container.addView(adUiContainer);


  Video adVideo = new Video(adTagUrl.toString(), Video.VideoType.MP4);
  adPlayer = new SimpleVideoPlayer(activity,
      adPlayerContainer,
      adVideo,
      "",
      true,
      0,
      fullscreenCallback);

  adPlayer.addPlaybackListener(adPlaybackListener);

  // Move the ad player's surface layer to the foreground so that it is overlaid on the content
  // player's surface layer (which is in the background).
  adPlayer.moveSurfaceToForeground();
  adPlayer.play();
  adPlayer.disableSeeking();
  adPlayer.setSeekbarColor(Color.YELLOW);
  adPlayer.hideTopChrome();
  adPlayer.setFullscreen(contentPlayer.isFullscreen());

  // Notify the callbacks that the ad has begun playing.
  for (VideoAdPlayer.VideoAdPlayerCallback callback : callbacks) {
    callback.onPlay();
  }
}
 
Example #10
Source File: VideoPlayerWithAdPlayback.java    From googleads-ima-android with Apache License 2.0 4 votes vote down vote up
/** Returns an implementation of the SDK's VideoAdPlayer interface. */
public VideoAdPlayer getVideoAdPlayer() {
  return mVideoAdPlayer;
}