[英]Showing an interstitial ad after a sound has finished
I'm fairly new to android development and learning as I go, please go easy on me... I'm working on a soundboard where I want to wait until after a sound is finished playing before an interstitial ad is displayed, my current code below doesn't initialise the ad:我对 android 开发和学习还很陌生,请放轻松……我正在制作一个音板,我想等到声音播放完毕后再显示插页式广告,我目前的下面的代码不会初始化广告:
button1 = (findViewById(R.id.button));
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
stopPlaying();
mp = MediaPlayer.create(MainActivity.this, R.raw.dontbeanidiot);
clickCount = clickCount + 1;
mp.start();
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
if (mp.isPlaying()) {
mp.stop();
mp.release();
if (clickCount == 10) {
mInterstitialAd.show();
clickCount = 0;
}
}
}
});
}
});
This is the code that does show the interstitial but on button press rather than after.这是显示插页式广告但在按钮按下而不是之后的代码。 What am I doing wrong?
我究竟做错了什么?
button2 = findViewById(R.id.button2);
button2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
stopPlaying();
mp = MediaPlayer.create(MainActivity.this, R.raw.wouldanidiot);
clickCount=clickCount+1;
if (clickCount==10) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
clickCount=0;
}
}
mp.start();
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
if (mp.isPlaying()) {
mp.stop();
mp.release();
}
}
});
}
});
I changed it to this and now it works as I wanted.我把它改成了这个,现在它可以按我的意愿工作了。 Yes, I'm an idiot.
是的,我是个白痴。
button1 = (findViewById(R.id.button));
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
stopPlaying();
mp = MediaPlayer.create(MainActivity.this, R.raw.dontbeanidiot);
clickCount = clickCount + 1;
mp.start();
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
if (mp.isPlaying()) {
mp.stop();
mp.release();
}
if (clickCount > 10) {
mInterstitialAd.show();
clickCount = 0;
}
}
});
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.