简体   繁体   English

奖励视频不会在第一次加载,但会在之后加载

[英]Rewarded Videos doesn't load the first time but loads after

My App has a button to open reward videos >> when this button is pressed for the first time, it toasts "Check your Internet connection", when hit the second or third time, it shows the video with no problems 我的应用程序有一个打开奖励视频的按钮>>第一次按下此按钮时,它会“检查您的互联网连接”,当第二次或第三次点击时,它会显示视频没有问题

    MobileAds.initialize(getActivity(), getString(R.string.VID_App_ID));
    mRewardVideoAd = MobileAds.getRewardedVideoAdInstance(getActivity());
    mRewardVideoAd.loadAd(getString(R.string.VID_App_Unit_ID), new AdRequest.Builder()
            .addTestDevice(getString(R.string.TestDeviceID))
            .build());
    mRewardVideoAd.setRewardedVideoAdListener(this);
    loadRewardedVideoAd();   

Here are the methods used : 以下是使用的方法:

 private void loadRewardedVideoAd() {
        mRewardVideoAd.loadAd(getString(R.string.VID_App_Unit_ID), new AdRequest.Builder()
                .addTestDevice(getString(R.string.TestDeviceID))
                .build());
    }



   @OnClick(R.id.button_more_money)
    public void more_money() {
        if (mRewardVideoAd.isLoaded()) {
            mRewardVideoAd.show();
        } else
            { 
             Toast.makeText(getActivity(), "Check your internet connection", Toast.LENGTH_LONG).show();
            loadRewardedVideoAd();
               }

    }


    @Override
    public void onResume() {
        mRewardVideoAd.resume(getActivity());
        super.onResume();
        loadRewardedVideoAd();
    }

Edit: Solved - It took some time and the solution was to load at onCreate() Thanks to Martin De Simone and Avi Levin 编辑:已解决 - 花了一些时间,解决方案是加载onCreate()感谢Martin De Simone和Avi Levin

Rewarded videos take time to load, your code is fine, the first time you are pressing, the video is loading and then when you press probably the video has already loaded. 奖励视频需要一段时间才能加载,您的代码很好,第一次按下时,视频正在加载,然后当您按下时可能已加载视频。

Try to toast something in the onAdLoaded to check this 尝试在onAdLoaded中烘烤一些东西来检查这个

As Martin said, RV ad takes a time to load. 正如Martin所说,RV广告需要一段时间来加载。 basically, it needs to download ~30-second video which takes sometimes few second. 基本上,它需要下载约30秒的视频,有时需要几秒钟。

I recommend using the SDK provided RewardedVideoAdListener interface which will help you know when the ad is ready to show. 我建议使用SDK提供的RewardedVideoAdListener界面,它可以帮助您了解广告何时可以展示。 furthermore, it will help you to understand the AdMob rewarded video ad's life cycle. 此外,它还可以帮助您了解AdMob奖励视频广告的生命周期。

In order to use it you need to do the following phases: 要使用它,您需要执行以下阶段:

  1. Implement RewardedVideoAdListener listener in your java class 在java类中实现RewardedVideoAdListener侦听器
  2. Override the following methods (I used Toast UI messages for visualization, it can be deleted) 覆盖以下方法(我使用Toast UI消息进行可视化,可以删除)

Code: 码:

@Override
public void onRewarded(RewardItem reward) {
    Toast.makeText(this, "onRewarded! currency: " + reward.getType() + "  amount: " +
        reward.getAmount(), Toast.LENGTH_SHORT).show();
}

@Override
public void onRewardedVideoAdLeftApplication() {
    Toast.makeText(this, "onRewardedVideoAdLeftApplication",
            Toast.LENGTH_SHORT).show();
}

@Override
public void onRewardedVideoAdClosed() {
    Toast.makeText(this, "onRewardedVideoAdClosed", Toast.LENGTH_SHORT).show();
}

@Override
public void onRewardedVideoAdFailedToLoad(int errorCode) {
    Toast.makeText(this, "onRewardedVideoAdFailedToLoad", Toast.LENGTH_SHORT).show();
}

@Override
public void onRewardedVideoAdLoaded() {
    Toast.makeText(this, "onRewardedVideoAdLoaded", Toast.LENGTH_SHORT).show();
}

@Override
public void onRewardedVideoAdOpened() {
    Toast.makeText(this, "onRewardedVideoAdOpened", Toast.LENGTH_SHORT).show();
}

@Override
public void onRewardedVideoStarted() {
    Toast.makeText(this, "onRewardedVideoStarted", Toast.LENGTH_SHORT).show();
}

BTW: before a show call, I recommend using isLoaded() method in order to if the AdMob is ready to show something, for example: 顺便说一句:在显示调用之前,我建议使用isLoaded()方法,以便AdMob准备好显示某些内容,例如:

if (mAd.isLoaded()) {
    mAd.show();
}

More information can be found inside Google AdMob doc's 可以在Google AdMob 文档中找到更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM