AdMob正在加载多个奖励视频 [英] AdMob loading multiple rewarded videos

查看:124
本文介绍了AdMob正在加载多个奖励视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Admob中设置了多个广告单元,每个都是一个奖励视频。我的问题是,根据观看的视频,我会获得不同的奖励,并且我只能加载一个视频 onCreate(),例如,这仅加载了AD_UNIT_3的视频:

I have multliple Ad Units setup in Admob, and each one is a rewarded video. My problem is I am rewarded different items depending on which video is watched, and I can only load one video onCreate() for example this loads only the video for AD_UNIT_3:

mAd.loadAd("AD_UNIT_1", new AdRequest.Builder().build());
mAd.loadAd("AD_UNIT_2", new AdRequest.Builder().build());
mAd.loadAd("AD_UNIT_3", new AdRequest.Builder().build());

onRewarded( )被调用,如果我无法控制从哪个视频(AD UNIT)显示,从而无法监听多个单元?

How am I supposed to have a listener that rewards the item when onRewarded() is called, if I do not have control over which video (AD UNIT) to display from and thus have a listener for multiple units?

我现在有一个解决方案设置,可以通过仅当我知道将要显示的视频时才从正确的广告单元中加载正确的视频。例如,当他们打开硬币页面时,我知道他们需要硬币视频,因此使用硬币的侦听器来奖励正确的商品。

I have a solution setup now that loads the correct video from the correct ad unit by only loading it when I know that is the video that will be shown. For example, when they open up a "Coins" page I know they need the "Coins" video, and thus use the listener for "Coins" to reward the right item.

此解决方案的最大问题是,广告加载当然需要10秒,许多用户会点击硬币页面并尝试在几秒钟内加载广告-我在下面添加了当前代码,该代码无法正常工作。

The big problem with this solution is the ad can take 10 seconds to load of course, and many users will hit that "Coins" page and try to load the ad within seconds - I have added my current code below that does not work.

我知道我在想这个错误,因为没有其他人遇到过这个问题:)我已经为此工作了很长时间,对此我将不胜感激。洞察力。谢谢!

I know I am thinking about this wrong because there is no one else with this problem :) I've been working on this for a long time and would appreciate any insight. Thank you!

onCreate()

    mAd = MobileAds.getRewardedVideoAdInstance(this);

    mAd.setRewardedVideoAdListener(new RewardedVideoAdListener() {
        @Override
        public void onRewarded(RewardItem rewardItem) {
            switch(Constants.currentAd) {
                case("BUST"):
                    Log.d("AD","BUST: onRewarded()");
                    reverseBust();
                    Constants.currentAd = "";
                    break;

                case("SKIPTRAVEL"):
                    Log.d("AD","SKIPTRAVEL: onRewarded()");
                    skipTravel();
                    Constants.currentAd = "";
                    break;

                case("REMOVEHEAT"):
                    Log.d("AD","REMOVEHEAT: onRewarded()");
                    removeHeat();
                    Constants.currentAd = "";
                    break;

                case("SKIPUPGRADEDEALER"):
                    Log.d("AD","SKIPUPGRADEDEALER: onRewarded()");
                    skipUpgradeDealer();
                    Constants.currentAd = "";
                    break;

                case("SKIPDEALER"):
                    Log.d("AD","SKIPDEALER: onRewarded()");
                    //skipDealer();
                    Constants.currentAd = "";
                    break;
            }

        }
        }`

正在加载视频

public void loadRewardedVideos(String name) {
    switch(name) {
        case("BUST"):
            Constants.currentAd="BUST";
            mAd.loadAd("AD_UNIT_ID_1", new AdRequest.Builder().build());
            break;
        case("SKIPTRAVEL"):
            Constants.currentAd="SKIPTRAVEL";
            mAd.loadAd("AD_UNIT_ID_2", new AdRequest.Builder().build());
            break;
        case("REMOVEHEAT"):
            Constants.currentAd="REMOVEHEAT";
            mAd.loadAd("AD_UNIT_ID_3", new AdRequest.Builder().build());
            break;
        case("SKIPUPGRADEDEALER"):
            Constants.currentAd="SKIPUPGRADEDEALER";
            mAd.loadAd("AD_UNIT_ID_4", new AdRequest.Builder().build());
            break;
        case("SKIPDEALER"):
            Constants.currentAd="SKIPDEALER";
            mAd.loadAd("AD_UNIT_ID_5", new AdRequest.Builder().build());
            break;
    }

}

谢谢!

推荐答案

您正在以错误的方式考虑。 mAd 被实例化,只能有一个。您只需要使用 mAd ...

You're thinking about this the wrong way. mAd is instanced, there can be only one. You need to handle the functionality and rewards using just one instance of mAd...

这篇关于AdMob正在加载多个奖励视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆