2015-10-26 138 views
0

我將admob添加到我的應用程序中,所以我希望應用程序可以在廣告結束後直接播放視頻而不必按播放。 由於廣告暫停了視頻。AdMob在播放視頻後

這裏是我的代碼:

private InterstitialAd Interstitial; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.video); 

    Interstitial = new InterstitialAd(this); 
    Interstitial.setAdUnitId("ca-app-pub-XXXXXXXXXXXXXXXXXX"); 

    Interstitial.setAdListener(new AdListener(){ 
     public void onAdClosed(){ 
      requestNewInterstitial(); 
      beginVideoStream(); 
     } 
    }); 
    requestNewInterstitial(); 

    Interstitial.setAdListener(new AdListener(){ 
     public void onAdLoaded() { 
      if (Interstitial.isLoaded()) { 
       Interstitial.show(); 
      } else { 
       beginVideoStream(); 
      } 
     } 
    }); 

    beginVideoStream(); 
} 


private void requestNewInterstitial() { 
    AdRequest adRequest = new AdRequest.Builder() 
       .build(); 

    Interstitial.loadAd(adRequest); 
} 

protected void displayInterstitial() { 
    // TODO Auto-generated method stub 
} 
public void onDismissScreen() { 
    // TODO Auto-generated method stub 
} 
public void onFailedToReceiveAd() { 
    // TODO Auto-generated method stub 
} 
public void onLeaveApplication() { 
    // TODO Auto-generated method stub 
} 
public void onPresentScreen() { 
    // TODO Auto-generated method stub 
} 

private void beginVideoStream(){ 
    VideoView vidView = (VideoView) findViewById(R.id.videoView1); 

    String vidAddress = "http://cdn.ebound.com/14/playlist.mp4"; 
    Uri vidUri = Uri.parse(vidAddress); 

    vidView.setVideoURI(vidUri); 
    vidView.start(); 

    MediaController vidControl = new MediaController(this); 
    vidControl.setAnchorView(vidView); 
    vidView.setMediaController(vidControl); 
} 

希望有人能幫助我感謝

回答

0

你的代碼看起來幾乎是正確的,除了通過調用onCreate()beginVideoStream()你開始你的視頻,然後當廣告無法加載或者已關閉,您將再次開始播放視頻。

這可能是什麼暫停您的視頻。

你不應該在onCreate()

啓動它