Android TV で Android 向け IMA SDK を使用する

IMA SDK for Android を使用する際に Android TV でアプリを適切に機能させるためのおすすめの方法がいくつかあります。

まず、Android 向け TV アプリの開発について十分に理解してください。具体的には、スタートガイドの説明に沿って、テレビ用にアクティビティが設定されていることを確認します。また、TV のナビゲーションを処理して、ユーザーが Android TV でアプリを適切に操作できるようにする必要があります。

スキップ可能な広告を処理する

この SDK は、[詳細] ボタンに対応する機能を削除するなどして、テレビに似たデバイス向けにスキップ可能なフォーマットを最適化します。SDK はデフォルトで、スキップが利用可能なときにスキップボタンにフォーカスを設定して、Android TV で広告をスキップできるようにします。そのため、スキップ可能な広告をサポートするため追加の作業は必要ありません。

これを構成するには、AdsRenderingSettings.setFocusSkipButtonWhenAvailable() を呼び出します。

サポートされている広告について詳しくは、互換性マトリックスをご覧ください。

VAST アイコンの代替画像を処理する

IMA SDK は、VAST アイコンの代替画像に対するユーザーの操作を検出してレンダリングし、処理します。アプリで ICON_TAPPED イベントと ICON_FALLBACK_IMAGE_CLOSED イベントをリッスンして、「広告の表示について」(WTA)を使用する広告の再生を処理する必要があります。

VAST アイコンの代替画像が表示されているかどうかをトラッキングするブール値を追加します。その後、ICON_TAPPEDICON_FALLBACK_IMAGE_CLOSED をリッスンし、VAST アイコンの代替画像の周囲の広告再生を処理します。この処理の例については、高度な例のコード スニペットをご覧ください。

app/src/main/java/com/google/ads/interactivemedia/v3/samples/videoplayerapp/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;