हमारा सुझाव है कि Android के लिए IMA SDK का इस्तेमाल करते समय, Android TV पर आपका ऐप्लिकेशन ठीक से काम करे. इसके लिए, यहां दिए गए सबसे सही तरीके अपनाएं.
Android के लिए टीवी ऐप्लिकेशन डेवलप करने के बारे में जानकारी पाकर शुरुआत करें. खास तौर पर, पक्का करें कि टीवी के लिए आपकी गतिविधि सेट अप हो. इसके बारे में शुरू करने के लिए गाइड में बताया गया है. आपको टीवी नेविगेशन को भी मैनेज करना होगा, ताकि यह पक्का किया जा सके कि लोग Android TV पर आपके ऐप्लिकेशन को आसानी से नेविगेट कर सकें.
स्किप किए जा सकने वाले विज्ञापनों को मैनेज करना
SDK, टीवी जैसे डिवाइसों के लिए स्किप किए जा सकने वाले फ़ॉर्मैट को ऑप्टिमाइज़ करता है. उदाहरण के लिए, ज़्यादा जानें बटन के साथ इंटरैक्ट करने की सुविधा हटाकर. डिफ़ॉल्ट रूप से, स्किप करने की सुविधा उपलब्ध होने पर SDK टूल, स्किप बटन पर फ़ोकस सेट करता है. इससे Android TV पर विज्ञापन को स्किप किया जा सकता है. इसलिए, स्किप किए जा सकने वाले विज्ञापनों को चलाने के लिए, अलग से कुछ करने की ज़रूरत नहीं है.
इसे कॉन्फ़िगर करने के लिए, AdsRenderingSettings.setFocusSkipButtonWhenAvailable()
पर कॉल करें.
कौनसे विज्ञापन फ़ॉर्मैट काम करते हैं, इस बारे में ज़्यादा जानने के लिए विज्ञापन फ़ॉर्मैट की जानकारी देखें.
वीएएसटी आइकॉन की फ़ॉलबैक इमेज मैनेज करना
IMA SDK, VAST आइकॉन फ़ॉलबैक इमेज के साथ उपयोगकर्ता के इंटरैक्शन का पता लगाता है, उन्हें रेंडर करता है, और मैनेज करता है. आपका ऐप्लिकेशन, ICON_TAPPED
और ICON_FALLBACK_IMAGE_CLOSED
इवेंट के लिए इवेंट लिसनर का इस्तेमाल करे, ताकि 'यह विज्ञापन क्यों दिखाया जा रहा है' (डब्ल्यूटीए) सुविधा का इस्तेमाल करने वाले विज्ञापनों के लिए, विज्ञापन के प्लेबैक को मैनेज किया जा सके.
यह ट्रैक करने के लिए कि VAST आइकॉन फ़ॉलबैक इमेज दिख रही है या नहीं, एक बूलियन जोड़ें. इसके बाद, VAST आइकॉन फ़ॉलबैक इमेज के आस-पास विज्ञापन चलाने के लिए, ICON_TAPPED
और ICON_FALLBACK_IMAGE_CLOSED
को सुनें. ऐडवांस उदाहरण में, इसे मैनेज करने का तरीका जानने के लिए, यहां दिया गया कोड स्निपेट देखें.
VideoPlayerController.java
// Copyright 2014 Google Inc. All Rights Reserved.
package com.google.ads.interactivemedia.v3.samples.videoplayerapp;
import android.app.UiModeManager;
import android.content.Context;
...
// Tracks if the SDK is playing an ad, since the SDK might not necessarily use
// the video player provided to play the video ad.
private boolean isAdPlaying;
// Tracks whether the SDK has a VAST icon fallback image showing.
private boolean isConnectedTvFallbackImageShowing = false;
// View that handles taps to toggle ad pause/resume during video playback.
private View playPauseToggle;
// View that we can write log messages to, to display in the UI.
private Logger log;
...
adsManager.addAdEventListener(
new AdEvent.AdEventListener() {
/** Responds to AdEvents. */
@Override
public void onAdEvent(AdEvent adEvent) {
...
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 ICON_TAPPED:
// The user has tapped a VAST icon fallback image. On Android
// mobile apps, the SDK will navigate to the landing page. On
// Connected TV devices, the SDK will present a modal dialog
// containing the VAST icon fallback image.
// Check if the app is running on a TV device.
UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) {
isConnectedTvFallbackImageShowing = true;
}
// Focus the IMA WebView for easier access to ad UI elements.
adsManager.focus();
break;
case PAUSED:
if (isConnectedTvFallbackImageShowing) {
// Do not show the controls; continue to leave the controls in
// the hands of the ads SDK.
break;
}
isAdPlaying = false;
videoPlayerWithAdPlayback.enableControls();
break;
case ICON_FALLBACK_IMAGE_CLOSED:
// The user has closed the VAST icon fallback image. This may
// be a good time to resume ad playback if the user is ready to
// continue playing the ad. This event only fires for Connected
// TV devices.
isConnectedTvFallbackImageShowing = false;
adsManager.resume();
break;
case RESUMED:
isAdPlaying = true;
videoPlayerWithAdPlayback.disableControls();
break;