Reputation: 61
if you can help me solve, I have a project where I have videos rewarded by admob. Everything goes well but I have a small inconvenience. The videos load when I start the app, but it takes me 20 seconds to load it. That's a long time and I want it to load in a few seconds. How can I make it take less? When I finish loading the video I see it. When finished viewing another video is loaded but this one if it loads super fast, in 1 second it is already loaded. How can I make it load as fast as I can when I start the app? Another problem I have is that some of my users do not upload the videos, they get Rewarded Video Ad Failed To Load, because it could happen? Only happens to some.
package com.android.proyect;
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);
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'
Upvotes: 1
Views: 1532
Reputation: 23
You can call loadRewardedVideoAd() function in onRewardedVideoAdClosed() and onRewarded()
Upvotes: 2