2014-04-17 94 views
0

你好,我想用AdColony SDK依次執行多個視頻,我的意思是當一個視頻完成時,另一個必須顯示。但不能讓它工作,第一個視頻完成另一個視頻不顯示。 這是我的代碼,我的onCreate方法:用AdColony依次執行多個視頻

@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回調,但沒有顯示出來。 請幫幫我嗎?提前致謝。

回答

2

新的AdColony視頻廣告直到onAdColonyAdAttemptFinished回調之後纔會準備就緒。此外,我們不建議讓按鈕以這種方式顯示五個視頻的想法,因爲無法始終確保此級別的廣告可用性。

話雖這麼說,對於這種可能的解決方法是使用一個處理器和一個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()方法,您目前已包括在內。請隨時通過[email protected]與我們聯繫,以便進行其他任何查詢。

+0

當我轉移到另一項活動或Backwark時,我的Adcolony廣告會運行一次。我的interstials廣告沒有顯示原因。 – Nepster