gpt4 book ai didi

android - 快速加载视频奖励 Admob 和 Android Studio?

转载 作者:行者123 更新时间:2023-11-30 00:51:31 25 4
gpt4 key购买 nike

如果你能帮我解决,我有一个项目,我有视频奖励的admob。一切顺利,但我有一点不便。当我启动应用程序时会加载视频,但加载它需要 20 秒。那是很长的时间,我希望它在几秒钟内加载。我怎样才能让它花费更少?当我完成加载视频时,我会看到它。观看完后会加载另一个视频,但如果加载速度超快,则此视频会在 1 秒内加载完毕。我怎样才能让它在我启动应用程序时尽可能快地加载?我遇到的另一个问题是我的一些用户没有上传视频,他们收到奖励视频广告加载失败,因为这可能发生?只发生在一些人身上。

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 项目

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 应用

    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'

最佳答案

可以在onRewardedVideoAdClosed()和onRewarded()中调用loadRewardedVideoAd()函数

关于android - 快速加载视频奖励 Admob 和 Android Studio?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40954181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com