0

您好,我想使用 AdColony SDK 按顺序执行多个视频,我的意思是当一个视频完成时,另一个必须显示。但无法让它工作,一个第一个视频完成另一个视频没有显示。这是我的代码,我的 onCreate 方法:

@Override
  public void onCreate( Bundle savedInstanceState )
  {
    super.onCreate(savedInstanceState);
    getActionBar().hide();
    // Configure ADC once early before any other ADC calls (except setCustomID/setDeviceID).
    AdColony.configure( this, "1.0", APP_ID, ZONE_ID_ONE_VIDEO );
    // version - arbitrary application version
    // store   - google or amazon

    // Disable rotation if not on a tablet-sized device (note: not
    // necessary to use AdColony).
    if ( !AdColony.isTablet() )
    {
      setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_PORTRAIT );
    }

    // Notify this object about confirmed virtual currency.
    AdColony.addV4VCListener( this );

    // Notify this object about ad availability changes.
    AdColony.addAdAvailabilityListener( this );

    setContentView( R.layout.videos_ads_activity );

    mAppPreferences = new AppPreferences(this);

    /*video1 = new AdColonyV4VCAd(WatchVideosActivity.ZONE_ID_ONE_VIDEO);
    video2 = new AdColonyV4VCAd(WatchVideosActivity.ZONES_FIVES_VIDEOS[1]).withListener(this);
    video3 = new AdColonyV4VCAd(WatchVideosActivity.ZONES_FIVES_VIDEOS[2]).withListener(this);
    video4 = new AdColonyV4VCAd(WatchVideosActivity.ZONES_FIVES_VIDEOS[3]).withListener(this);
    video5 = new AdColonyV4VCAd(WatchVideosActivity.ZONES_FIVES_VIDEOS[4]).withListener(this);*/


    showOneVideo = (Button) findViewById(R.id.buttonShowOneVideo);
    showOneVideo.setOnClickListener(
            new View.OnClickListener()
            {
              public void onClick( View v )
              {
                  AdColonyV4VCAd v4vc_ad = new AdColonyV4VCAd()
                    .withListener( WatchVideosActivity.this);

                  if(v4vc_ad.getAvailableViews() == 0){
                      Toast.makeText(WatchVideosActivity.this, "Loading ads", Toast.LENGTH_SHORT).show();
                  }else{
                      v4vc_ad.show();
                  }
              }
            });

    showFiveVideos = (Button) findViewById(R.id.buttonShowFiveVideos);
    showFiveVideos.setOnClickListener(
            new View.OnClickListener()
            {
              public void onClick( View v )
              {
                  v4vc_ad = new AdColonyV4VCAd(ZONE_ID_ONE_VIDEO)
                    .withListener( WatchVideosActivity.this);

                  if(v4vc_ad.getAvailableViews() == 0){
                      Toast.makeText(WatchVideosActivity.this, "Loading ads", Toast.LENGTH_SHORT).show();
                  }else{
                      v4vc_ad.show();
                  }
              }
            });
}

我班级的其余部分(我没有放置实例变量,但已声明):

      public void onPause()
  {
    super.onPause();
    AdColony.pause();
  }

  public void onResume()
  {
    super.onResume();
    AdColony.resume( this );
  }

  // Reward Callback
  public void onAdColonyV4VCReward( AdColonyV4VCReward reward )
  {
    if (reward.success())
    {
      //Guardamos el reward en mi preference
      mAppPreferences.setCoins(mAppPreferences.getCoins() + reward.amount());
      Log.d("AdColony", "rewaerdCallback listener");
    }
  }

  // Ad Started Callback - called only when an ad successfully starts playing
  public void onAdColonyAdStarted( AdColonyAd ad )
  {
    Log.d("AdColony", "onAdColonyAdStarted");
  }

  //Ad Attempt Finished Callback - called at the end of any ad attempt - successful or not.
  public void onAdColonyAdAttemptFinished( AdColonyAd ad )
  {

          try {
                Thread.sleep(1500);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        AdColonyV4VCAd v4vc_ad = new AdColonyV4VCAd()
        .withListener( WatchVideosActivity.this);

        v4vc_ad.show();
      }
  }

我在 onAdColonyAdAttemptFinished 回调中创建了一个新视频,但这没有显示出来。请问可以帮我吗?提前致谢。

4

1 回答 1

2

在 onAdColonyAdAttemptFinished 回调之后,新的 AdColony 视频广告才会准备就绪。此外,不建议使用按钮以这种方式显示五个视频,因为无法始终确保这种级别的广告可用性。

话虽如此,一个可能的解决方法是使用 Handler 和 Runnable ,如下所示:

//In your onCreate method w/ the variables declared globally
handler = new Handler();
runnable = new Runnable()
{
  public void run()
  {
    AdColonyV4VCAd ad = new AdColonyV4VCAd( ZONE_ID ).withListener( listener );
    ad.show();
  }
};

...
...
...

//At the end of your onAdColonyAdAttemptFinished method,
//delay a second or so to allow your Activity to regain 
//control before attempting to launch the new advertisement.
handler.postDelayed( runnable, 1000 );

使用此解决方案,您当前包含的 Thread.sleep() 也不再需要。如有任何其他疑问,请随时通过 support@AdColony.com 直接与我们联系。

于 2014-04-18T17:11:52.167 回答