네이티브 동영상 광고

MediaContent

네이티브 광고 액세스 권한을 부여하여 MediaContent 드림 객체에 대한 정보를 가져오는 데 사용되는 동영상 또는 이미지일 수 있습니다. 또한 동영상 광고 재생을 제어하고 지정할 수 있습니다. 다음을 호출하여 MediaContent 객체를 가져올 수 있습니다. NativeAd.getMediaContent()

MediaContent 객체에는 가로세로 비율 및 지정할 수 있습니다. 다음 스니펫은 가로세로 비율을 가져오는 방법과 재생 시간을 설정할 수 있습니다.

자바

if (myNativeAd.getMediaContent().hasVideoContent()) {
  float mediaAspectRatio = myNativeAd.getMediaContent().getAspectRatio();
  float duration = myNativeAd.getMediaContent().getDuration();
  ...
}

Kotlin

if (myNativeAd.getMediaContent().hasVideoContent()) {
  val mediaAspectRatio: Float = myNativeAd.getMediaContent().getAspectRatio()
  val duration: Float = myNativeAd.getMediaContent().getDuration()
  ...
}

동영상 이벤트 콜백

특정 동영상 이벤트를 처리하려면 추상 VideoLifecycleCallbacks 클래스로 이동하여 다음을 호출합니다. setVideoLifecycleCallbacks() (VideoController) 그런 다음 관심 있는 콜백만 재정의합니다.

자바

myNativeAd.getMediaContent().getVideoController()
        .setVideoLifecycleCallbacks(new VideoLifecycleCallbacks() {

  /** Called when video playback first begins. */
  @Override
  public void onVideoStart() {
    // Do something when the video starts the first time.
    Log.d("MyApp", "Video Started");
  }

  /** Called when video playback is playing. */
  @Override
  public void onVideoPlay() {
    // Do something when the video plays.
    Log.d("MyApp", "Video Played");
  }

  /** Called when video playback is paused. */
  @Override
  public void onVideoPause() {
    // Do something when the video pauses.
    Log.d("MyApp", "Video Paused");
  }

  /** Called when video playback finishes playing. */
  @Override
  public void onVideoEnd() {
    // Do something when the video ends.
    Log.d("MyApp", "Video Ended");
  }

  /** Called when the video changes mute state. */
  @Override
  public void onVideoMute(boolean isMuted) {
    // Do something when the video is muted.
    Log.d("MyApp", "Video Muted");
  }
});

Kotlin

myNativeAd.getMediaContent().getVideoController().setVideoLifecycleCallbacks {

  /** Called when video playback first begins. */
  override fun onVideoStart() {
    // Do something when the video starts the first time.
    Log.d("MyApp", "Video Started")
  }

  /** Called when video playback is playing. */
  override fun onVideoPlay() {
    // Do something when the video plays.
    Log.d("MyApp", "Video Played")
  }

  /** Called when video playback is paused. */
  override fun onVideoPause() {
    // Do something when the video pauses.
    Log.d("MyApp", "Video Paused")
  }

  /** Called when video playback finishes playing. */
  override fun onVideoEnd() {
    // Do something when the video ends.
    Log.d("MyApp", "Video Ended")
  }

  /** Called when the video changes mute state. */
  override fun onVideoMute(boolean isMuted) {
    // Do something when the video is muted.
    Log.d("MyApp", "Video Muted")
  }
}