我创建与LibGDX一个游戏,希望把有好报的视频就可以了,但我想不出我该怎么做。
我已经显示了AdMob的横幅本教程: https://www.youtube.com/watch?v=cwAN4LMXo58
我已经看到了这个问题,但不明白的地方把这个代码:
public void showVideoAd(){
runOnUiThread(new Runnable() {
public void run() {
if (mAd.isLoaded()) {
mAd.show();
} else {
loadRewardedVideoAd();
}
}
});
}
public boolean hasVideoReward(){
return isRewardLoaded;
//return mAd.isLoaded(); // -> must be called on the main UI thread.
}
(首先是有没有在它宣布MAD): 在libGDX奖励视频广告示例
并使用几个sorces我做了一些实验是最后一个:
AdHandler.java:
public interface AdHandler {
public void showVideo();
}
AndroidLauncher:
public class AndroidLauncher extends AndroidApplication implements AdHandler {
RewardedVideoAd rewardedVideoAd;
@Override
public void showVideo() {
if (rewardedVideoAd.isLoaded()) {
rewardedVideoAd.show();
}
}
Handler handler = new Handler();
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(new Restart(this), config);
rewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
rewardedVideoAd.setRewardedVideoAdListener(new RewardedVideoAdListener() {
@Override
public void onRewardedVideoAdLoaded() {
}
@Override
public void onRewardedVideoAdOpened() {
}
@Override
public void onRewardedVideoStarted() {
}
@Override
public void onRewardedVideoAdClosed() {
}
@Override
public void onRewarded(RewardItem rewardItem) {
}
@Override
public void onRewardedVideoAdLeftApplication() {
}
@Override
public void onRewardedVideoAdFailedToLoad(int i) {
}
});
loadRewardedVideoAd();
}
private void loadRewardedVideoAd() {
rewardedVideoAd.loadAd("ca-app-pub-3940256099942544/5224354917", new AdRequest.Builder().build());
}
}
然后,我对机器人类的代码:
AdHandler adHandler;
public Restart(AdHandler handler) {
this.adHandler = handler;
}
而finnally我只是打电话
adHandler.showVideo();
在渲染()是什么赋予了错误
java.lang.IllegalStateException:isLoaded必须在主UI线程调用。
(我真的不知道是什么意思)
如果任何人都可以给我一份有LibGDX + AdMob的奖励影片完整的工作项目将是真棒。
[编辑]
所以一些测试,我已经能够使它工作后,我才不得不改变
@Override
public void showVideo() {
if (rewardedVideoAd.isLoaded()) {
rewardedVideoAd.show();
}
}
至
@Override
public void showVideo() {
runOnUiThread(new Runnable() {
@Override public void run() {
if (rewardedVideoAd.isLoaded()) {
rewardedVideoAd.show();
}
}
});
}
而且解决了我前面说的错误。
所以,现在的代码是这样的:
AdHandler.java:不变
Andoid启动:
public class AndroidLauncher extends AndroidApplication implements AdHandler {
RewardedVideoAd rewardedVideoAd;
@Override
public void showVideo() {
runOnUiThread(new Runnable() {
@Override public void run() {
if (rewardedVideoAd.isLoaded()) {
rewardedVideoAd.show();
}
}
});
}
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(new Restart(this), config);
MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");
rewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
rewardedVideoAd.loadAd("ca-app-pub-3940256099942544/5224354917", new AdRequest.Builder().build());
rewardedVideoAd.setRewardedVideoAdListener(new RewardedVideoAdListener() {
@Override
public void onRewardedVideoAdLoaded() {
}
@Override
public void onRewardedVideoAdOpened() {
}
@Override
public void onRewardedVideoStarted() {
}
@Override
public void onRewardedVideoAdClosed() {
rewardedVideoAd.loadAd("ca-app-pub-3940256099942544/5224354917", new AdRequest.Builder().build());
}
@Override
public void onRewarded(RewardItem rewardItem) {
}
@Override
public void onRewardedVideoAdLeftApplication() {
}
@Override
public void onRewardedVideoAdFailedToLoad(int i) {
}
});
}
}
Andoid类:
public class RewVideo extends ApplicationAdapter {
AdHandler adHandler;
public Restart(AdHandler handler) {
this.adHandler = handler;
}
@Override
public void create () {
}
@Override
public void render () {
if (Gdx.input.justTouched()) {
adHandler.showVideo();
}
}
然而,它填补了我的日志用奇怪的消息和异常:
W /广告:调用火力地堡getInstance方法错误。 抛出java.lang.ClassNotFoundException:没有找到路径类“com.google.android.gms.measurement.AppMeasurement”:
谷歌手机广告SDK不会与火力地堡整合。 AdMob广告/ Firbase整合需要最新的火力地堡SDK罐子,但火力地堡SDK丢失或过时
W /广告:服务器参数:{...}
W / DynamiteModule:为com.google.android.gms.ads.dynamite本地模块描述符类未找到。
W / OkHttpClient:所述的连接https://googleads.g.doubleclick.net/被泄露。 你忘了关闭响应主体?
W /的MessageQueue:处理程序(android.os.Handler){c84505c}上的死螺纹java.lang.IllegalStateException发送消息到一个处理程序:处理程序(android.os.Handler){c84505c}发送消息到一个处理程序上的死螺纹
W / ExoPlayerImplInternal:释放之后发送消息(1)。 消息被忽略。
E / ACodec:[OMX.google.h264.decoder]上输出到DynamicANWBuffer setPortMode失败瓦特/ ERR -1010
而且在播放视频时出现该消息像每秒一次:
W /合子:尝试删除非本地JNI参考,倾销线
而更多的不是被多吨的消息,我也注意到,有每一个的这两个消息:“广告加载完成后”,“广告开放”和“广告已关闭”
这是正常的吗?