广告播放视频后的AdMob

时间:2015-10-26 18:37:17

标签: android 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);
}

希望有人能帮助我,谢谢

1 个答案:

答案 0 :(得分:0)

您的代码看起来几乎正确,除非您beginVideoStream()中的onCreate()正在启动您的视频,然后当广告无法加载或已关闭时您再次启动视频。

这可能就是暂停你的视频。

您不应该在onCreate()

中启动它