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);
}
希望有人能幫助我感謝