0

每次我运行代码时,它都会调用 onRewardedVideoAdFailedToLoad(int i) 函数。我正在使用codelabs 示例。抱歉英语不好,谢谢你帮助我。这是我的代码。我用了很多教程。有什么我做错了吗?

或者我只是错过了一些步骤?

public class Rewardedvideo extends AppCompatActivity implements 
RewardedVideoAdListener {
RewardedVideoAd mAd;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_rewardedvideo);
    MobileAds.initialize(getApplicationContext(), "ca-app-pub-
3940256099942544~3347511713");

    mAd=MobileAds.getRewardedVideoAdInstance(Rewardedvideo.this);
    mAd.setRewardedVideoAdListener(this);
    loadrewardedvideoAd();
}
public void loadrewardedvideoAd(){
    if(!mAd.isLoaded()){
        mAd.loadAd("ca-app-pub-3940256099942544/5224354917",new 
AdRequest.Builder().build());
    }
}
public void startvideo(){
    if(mAd.isLoaded()){
        mAd.show();
    }
    else {
        mAd.loadAd("ca-app-pub-3940256099942544/5224354917",new 
AdRequest.Builder().build());
        mAd.show();
    }
}
@Override
public void onRewarded(RewardItem reward) {
    Toast.makeText(this, "onRewarded! currency: " + reward.getType() + "  
amount: " +
            reward.getAmount(), Toast.LENGTH_SHORT).show();
    // Reward the user.
}

@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();
    startvideo();
}

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

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

@Override
public void onPause() {
    mAd.pause(this);
    super.onPause();
}

@Override
public void onDestroy() {
    mAd.destroy(this);
    super.onDestroy();
}
}

这是我的代码。我用了很多教程。有什么我做错了吗?

或者我只是错过了一些步骤?

4

1 回答 1

0

我认为这不是获取视频源。过几次再试

于 2018-05-19T21:25:10.483 回答