Load fast video rewarded AdMob and Android Studio?

3

I wish you could help me solve this problem that I have. I have a project in which I have the videos awarded by admob. Everything is fine, but I have a small inconvenience. When I start the application the video loads me, but it takes 20 seconds to load it. That is a long time and I want it to be loaded in a few seconds. How can I make it take less? But the strange thing that happens to me is that when I finish watching the video I have automatically put it to load another, but it loads very fast, in 1 second it is already loaded. How can I make it load as fast as I can when I start the application?

package com.android.proyect;

import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.reward.RewardItem;
import com.google.android.gms.ads.reward.RewardedVideoAdListener;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.messaging.FirebaseMessaging;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.reward.RewardedVideoAd;

import static android.graphics.BitmapFactory.decodeResource;
import static android.view.Window.FEATURE_LEFT_ICON;

public class Welcome extends AppCompatActivity{


    private RewardedVideoAd mRewardedVideoAd;
    private static final String AD_UNIT_ID = "ca-app-pub-000000000000000/00000000"; //My code

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        // Get the view from singleitemview.xml
        setContentView(R.layout.activity_welcome);

        MobileAds.initialize(this, APP_ID);

        probarboton = (Button) findViewById(R.id.button4);

        //Anuncio probar video
        mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
        mRewardedVideoAd.setRewardedVideoAdListener(new RewardedVideoAdListener()
        {

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

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

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

            @Override
            public void onRewardedVideoAdClosed()
            {
                Toast.makeText(Welcome.this, "onRewardedVideoAdClosed", Toast.LENGTH_SHORT).show();
                // Preload the next video ad.
                loadRewardedVideoAd();
            }

            @Override
            public void onRewarded(RewardItem rewardItem)
            {
                textView4.setText(String.format(Locale.getDefault(),"you got %d %s!", rewardItem.getAmount(), rewardItem.getType()));
            }

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

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

        probarboton.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View arg0)
            {
                Log.i("probar","video");
                System.out.println("click boton probar video");
                if (mRewardedVideoAd.isLoaded()) {
                    mRewardedVideoAd.show();
                }
            }
        });

        loadRewardedVideoAd();
    }

    private void loadRewardedVideoAd() {
        AdRequest adRewardRequest = new AdRequest.Builder()
                .build();
        mRewardedVideoAd.loadAd(AD_UNIT_ID, adRewardRequest );
    }

}

build.gradle proyect

dependencies {
    classpath 'com.android.tools.build:gradle:2.2.2'
    classpath 'com.google.gms:google-services:3.0.0'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

build.gradle app

    dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile 'com.android.support:support-v4:24.2.1'
    compile 'com.koushikdutta.ion:ion:2.1.9'
    compile 'com.android.support:support-vector-drawable:24.2.1'
    compile 'com.github.snowdream.android:smartimageview:0.0.2'
    testCompile 'junit:junit:4.12'
    compile 'com.google.android.gms:play-services-ads:9.4.0'
    compile 'com.google.firebase:firebase-ads:9.4.0'
    compile 'com.google.firebase:firebase-core:9.4.0'
    compile 'com.google.firebase:firebase-messaging:9.4.0'
    compile 'com.squareup.okhttp3:okhttp:3.4.1'
    compile files('libs/UnityAdsAdapter.jar')

}
apply plugin: 'com.google.gms.google-services'
    
asked by juansanchez1993 04.12.2016 в 21:53
source

1 answer

2

I see what you have in your code:

import com.google.android.gms.ads.AdView;

But actually you use RewardedVideoAd which is correct:

import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.reward.RewardedVideoAd;
import com.google.android.gms.ads.reward.RewardedVideoAdListener;

I think you need to initialize the ads when loading your application

 // Inicializar el SDK.
    MobileAds.initialize(this, APP_ID);
 //Anuncio probar video
    mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
 ...
 ...

I recommend you check the implementation of this example:

link

the method loadRewardedVideoAd() :

private void loadRewardedVideoAd() {
    if (!mRewardedVideoAd.isLoaded()) {
        mRewardedVideoAd.loadAd(AD_UNIT_ID, new AdRequest.Builder().build());
    }
}

and the showRewardedVideo method that you would load when you clicked on the button:

private void showRewardedVideo() {
    mShowVideoButton.setVisibility(View.INVISIBLE);
    if (mRewardedVideoAd.isLoaded()) {
        mRewardedVideoAd.show();
    }
}


  probarboton.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View arg0)
            {
                Log.i("probar","video");
                showRewardedVideo();
                /*System.out.println("click boton probar video");
                if (mRewardedVideoAd.isLoaded()) {
                    mRewardedVideoAd.show();
                }*/
            }
        });
    
answered by 04.12.2016 в 22:30