6. Video Ad‎ > ‎

4) Cocos2dx

Before starting this chapter, be sure that you already finished SDK settings. If not, check  [6) Cocos2dx Settings] first.

For video Ad, you have to load a video Ad by invoking prepareVideoAd() method and showVdieoAd() to play it. Once you have invoked prepareVideoAd() method, next video Ads are being loaded automatically at background task.

[Loading a Video Ad]

To load a video Ad, you have to invoke prepareVideoAd() method of TnkAdPlugin. First parameter is the name of Display Logic. (See 5) Display Logic for detail) and second parameter is the number to identify EventHandler. (See B. EventHandler for detail.) EventHandler is used for receiving events of video loading.

Prepare a Video Ad

#include "TnkAdPlugin.h"


bool HelloWorld::init() 

{

    TnkAdPlugin::prepareVideoAd("intro_video", 9);

    

    // ...

}


[EventHandler]

By EventHandler, you can get events releated to video Ad such as loading completion and closing video ad and can implements any logics you need for each events.
EventHandler is also used for getting result from async invocations such as querying points and withdrawing points and used for getting events from interstitial Ads and video Ads. See [EventHandler] for detail.

Events related to video Ads are as followings.
  • onClose(int handleId, int type) : Invoked when video Ad is closed. Reason code is passed in type parameter.
    • TNK_CLOSE_SIMPLE (0) : User closed the video Ad by clicking close button or pressing back-key.
    • TNK_CLOSE_CLICK (1) : User clicked the download button after watching video.
  • onLoad(int handleId, ) : Invoked when a video Ad has successfully loaded.
  • onShow(int handleId, ) : Invoked when video Ad is shown up.
  • onVideoCompleted(int handleId, int skipped) : Invoked when user completed watching video Ad. If user clicked skip button while watch video, 1 is passed in the parameter, otherwise 0 is passed.
  • onFailure(int handleId, int errCode) : Invoked when a video loading has failed and you have invoked prepareVideoAdOnce().
[Video Ad Sample]

TnkAdEventHandler 예시

bool HelloWorld::init()

{

    TnkAdPlugin::prepareVideoAd("intro_video", 9);


}


// TnkAdEvnetHandler

void HelloWorld::onLoad(int handlerId) {

if (handlerId == 9) {

TnkAdPlugin::showVideoAd("intro_video");

}

}


void HelloWorld::onVideoCompleted(int handlerId, int skipped) {

    //  ...

}


 
[Video Ad APIs]

- TnkPlugin::prepareVideoAd()
Method
  - void TnkPlugin::prepareVideoAd(const char *displayLogic)
  - void TnkPlugin::prepareVideoAd(const char *displayLogic)
  - void TnkPlugin::prepareVideoAd(const char *displayLogic, int handleId)

Description
   Load a video Ad. Once the video ad is loaded, you can play it by invoking showVideoAd() method.

Parameters
 Name Description
 displayLogic name of Display Logic. (See 5) Display Logic for detail)
 handleId number to identify an EventHandler

- TnkPlugin::prepareVideoAdOnce()
Method
  - void TnkPlugin::prepareVideoAdOnce(const char *displayLogic, int handleId)

Description
    Load a video Ad just once. If you want to load a video again, you have to invoke this API again. Once the video ad is loaded, you can play it by invoking showVideoAd() method. If loading a video has failed, onFailure() Event is invoked.

Parameters
 Name Description
 displayLogic name of Display Logic. (See 5) Display Logic for detail)
 handleId number to identify an EventHandler

- TnkPlugin::showVideoAd()

Method
  - void TnkPlugin::showVideoAd()
  - void TnkPlugin::showVideoAd(const char *displayLogic)

Description
  Play a video Ad loaded by prepareVideoAd() method.

- TnkPlugin::hasVideoAd()

Method
  - bool TnkPlugin::hasVideoAd(const char *displayLogic)

Description
   Returns true if a video Ad is loaded and ready for playing.
Comments