नेटिव वीडियो विज्ञापन

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