完成观看视频广告时增加

时间:2017-02-14 11:47:10

标签: android video increment ads revmob

我希望在完成观看视频广告时增加。我在按钮点击时调用startRevMobSession()功能,但是当没有可用视频时它也会增加..任何人请告诉我它的正确实现。 我正在使用Android Studio

双重计数器= 0.0;

Double adding = 0.0005;

String strCounter;

SharedPreferences sharedpreferences;

RevMob revmob;
RevMobFullscreen video;
private boolean videoIslodaded;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_video1);
}

public void startRevMobSession() {
    videoIslodaded = false;
    //RevMob's Start Session method:
    revmob = RevMob.startWithListener(this, new RevMobAdsListener() {
        @Override
        public void onRevMobSessionStarted() {
            loadVideo(); //Cache the video once the session is stared
        }
        @Override
        public void onRevMobSessionNotStarted(String message) {
            //If the session fails, no ad will be displayed.
        }
    },"<YOUR_APP_ID>");
}

public void loadVideo(){
    video = revmob.createVideo(this,new RevMobAdsListener(){
        @Override
        public void onRevMobVideoLoaded() {
            videoIslodaded = true; //Video ready to be displayed
            showVideo();
        }
        @Override
        public void onRevMobVideoStarted() {
            videoIslodaded = false;
        }
        @Override
        public void onRevMobAdNotReceived(String message) {
            videoIslodaded = false; //Ad failed to load;
        }
    });
}

public void showVideo(){
    if(videoIslodaded) video.showVideo();
}

public void watch1_btn(View view){

    startRevMobSession();

    sharedpreferences = getSharedPreferences("MyPREFERENCES", Context.MODE_PRIVATE);
    counter = Double.longBitsToDouble(sharedpreferences.getLong("key",Double.doubleToLongBits(0)));
    counter = counter+adding;
    strCounter = Double.toString(counter);

    sharedpreferences = getSharedPreferences("MyPREFERENCES", Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedpreferences.edit();
    editor.putLong("key", Double.doubleToRawLongBits(counter));
    editor.commit();
}  
}

2 个答案:

答案 0 :(得分:0)

添加VideoFinished侦听器:

public void loadVideo(){
    video = revmob.createVideo(this,new RevMobAdsListener(){
        @Override
        public void onRevMobVideoLoaded() {
            videoIslodaded = true; //Video ready to be displayed
            showVideo();
        }

        @Override
        public void onRevMobVideoStarted() {
            videoIslodaded = false;
        }

        @Override
        public void onRevMobAdNotReceived(String message) {
            videoIslodaded = false; //Ad failed to load;
        }

        @Override
        public void onRevMobVideoFinished(){
            Log.w("RevMob video finished playing");
            //Add your count here
        }
    });
}

如果您的视频获得奖励,您也可以添加此监听器(您需要查看完整视频):

    @Override
    public void onRevMobRewardedVideoFinished() {
         Log.w("RevMob Rewarded Video finished playing.");
    }

    @Override
    public void onRevMobRewardedVideoCompleted() {
        Log.w("RevMob Rewarded Video completed. You earned a coin!");
        //Add your count here
    }

答案 1 :(得分:0)

RevMob AdNetwork支持两种类型的视频。

  1. 视频
  2. 奖励视频
  3. 第一种类型是普通视频,每当您想要显示视频时使用。将屏幕从一个屏幕转移到另一个屏幕时。当我检查您的要求时,我建议您使用奖励视频。如果你仍然想坚持视频广告没有问题。如果有视频则调用showVideo(),否则会增加您的值。

    public void loadVideo(){
    
            video = revmob.createVideo(currentActivity,new RevMobAdsListener(){
                @Override
                public void onRevMobVideoLoaded() {
                    videoIsLoaded = true; //Video ready to be displayed
                }
                @Override
                public void onRevMobVideoStarted() {
                    videoIsLoaded = false;
                }
                @Override
                public void onRevMobAdNotReceived(String message) {
                    videoIsLoaded = false; //Ad failed to load;
                }
    
                @Override
                public void onRevMobAdClicked() {
                    Log.i("RevMob", "Video clicked.");
                }
    
                @Override
                public void onRevMobAdDismissed() {
                    Log.i("RevMob", "Video dismissed.");
                }
    
    
                @Override
                public void onRevMobVideoNotCompletelyLoaded() {
                    Log.i("RevMob", "Video has not been completely loaded.");
                    //You tried to show it but it's not loaded yet
                }
    
                @Override
                public void onRevMobVideoFinished(){
                    Log.i("RevMob", "Video finished playing");
                }
            });
        }
    
    
        public void showVideo(){
            if(videoIsLoaded) {
    
                 sharedpreferences = getSharedPreferences("MyPREFERENCES", Context.MODE_PRIVATE);
                 counter = Double.longBitsToDouble(sharedpreferences.getLong("key",Double.doubleToLongBits(0)));
                 counter = counter+adding;
                 strCounter = Double.toString(counter);
    
                 sharedpreferences = getSharedPreferences("MyPREFERENCES", Context.MODE_PRIVATE);
                 SharedPreferences.Editor editor = sharedpreferences.edit();
                 editor.putLong("key", Double.doubleToRawLongBits(counter));
                 editor.commit();
                 video.showVideo();                  
            }
            else loadVideo();
        }
    

    第二种类型适合您的要求。首先调用loadVideo()并附加监听器。通过onRevMobRewardedVideoLoaded()方法加载视频时启用标记。通过该标志检查您的奖励视频是否已准备好显示,如果是,则显示奖励对话框(UI)并通过该对话框按钮界面调用showRewardedVideo()

    public void loadRewardedVideo(){
            rewardedVideo = revmob.createRewardedVideo(currentActivity, new RevMobAdsListener(){
                @Override
                public void onRevMobRewardedVideoLoaded() {
                    rewardedVideoIsLoaded = true;
                    Log.i("RevMob","Rewarded Video ready to be displayed");
                }
                @Override
                public void onRevMobAdNotReceived(String message) {
                    rewardedVideoIsLoaded = false;
                    Log.i("RevMob","Rewarded Video failed to load");
                }
    
                @Override
                public void onRevMobAdDismissed() {
                    Log.i("RevMob", "Video dismissed.");
                }
    
                @Override
                public void onRevMobRewardedVideoNotCompletelyLoaded() {
                    Log.i("RevMob", "RevMob Rewarded Video not completely loaded.");
                    //You tried to show it but it's not loaded yet
                }
    
                @Override
                public void onRevMobRewardedVideoStarted() {
                    rewardedVideoIsLoaded = false;
                }
                @Override
                public void onRevMobRewardedVideoCompleted() {
                    Log.i("RevMob", "Rewarded Video completed. You earned a coin!");
                    //User dismissed post-roll static ad
    
                 sharedpreferences = getSharedPreferences("MyPREFERENCES", Context.MODE_PRIVATE);
                 counter = Double.longBitsToDouble(sharedpreferences.getLong("key",Double.doubleToLongBits(0)));
                 counter = counter+adding;
                 strCounter = Double.toString(counter);
    
                 sharedpreferences = getSharedPreferences("MyPREFERENCES", Context.MODE_PRIVATE);
                 SharedPreferences.Editor editor = sharedpreferences.edit();
                 editor.putLong("key", Double.doubleToRawLongBits(counter));
                 editor.commit();
    
    
                    loadRewardedVideo();
                }
                @Override
                public void onRevMobAdClicked() {
                    Log.i("RevMob", "Rewarded Video clicked. You earned a coin!");
                    //User clicked on post-roll static ad
                }
    
                @Override
                public void onRevMobRewardedVideoFinished() {
                    Log.i("RevMob", "RevMob Rewarded Video finished playing.");
                    //The video itself reached its end
                    loadRewardedVideo();
                }
    
                @Override
                public void onRevMobRewardedPreRollDisplayed() {
                    Log.i("RevMob", "RevMob Rewarded Video Pre-Roll displayed");
                }
            });
        }
    
     public boolean showRewardedVideo(){
        if(rewardedVideoIsLoaded) rewardedVideo.showRewardedVideo();
        return rewardedVideoIsLoaded;
    }
    

    onRevMobRewardedVideoCompleted()侦听器方法中增加你的价值。