מודעות וידאו מותאמות

MediaContent

מודעות מותאמות לספק גישה MediaContent שמשמש לקבלת מידע על תוכן מדיה, שיכול להיות סרטון או תמונה. הוא משמש גם כדי לשלוט בהפעלה של מודעות וידאו ולהאזין אירועי הפעלה. אפשר לקבל את האובייקט MediaContent באמצעות קריאה NativeAd.getMediaContent().

האובייקט MediaContent מכיל מידע כמו יחס גובה-רוחב ו כל משך הסרטון. הקטע הבא מראה איך לקבל את יחס הגובה-רוחב משך הזמן של מודעה מותאמת.

Java

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. לאחר מכן, מבטלים רק את הקריאות החוזרות שחשובות לכם.

Java

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")
  }
}