6. Video Ad‎ > ‎

3) Unity

Before starting this chapter, be sure that you already finished SDK settings. If not, check 5) Unity 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]

Once your app has started, you have to call initialization method as belows.

Initialize

public class TnkUITest : MonoBehaviour {

    void Start ()
    {
        TnkAd.Plugin.Instance.initInstance ();
    }
    

}


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

Prepare a Video Ad


TnkAd.Plugin.Instance.prepareVideoAd("intro_video""testhandler");


[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 type) : Invoked when video Ad is closed. Reason code is passed in type parameter.
    • CLOSE_SIMPLE (0) : User closed the video Ad by clicking close button or pressing back-key.
    • CLOSE_CLICK (1) : User clicked the download button after watching video.
  • onLoad() : Invoked when a video Ad has successfully loaded.
  • onShow() : Invoked when video Ad is shown up.
  • onVideoCompleted(boolean skipped) : Invoked when user completed watching video Ad. If user clicked skip button while watch video, true is passed in the parameter.
  • onFailure(int errCode) : Invoked when a video loading has failed and you have invoked prepareVideoAdOnce().
[Video Ad Sample]

EventHandler Sample

public class TnkUITest : MonoBehaviour {

    void Start ()
    {
        TnkAd.Plugin.Instance.initInstance ();
    }
    
    void Update ()
    {
    }
    
    void OnGUI ()
    {
        if (GUI.Button (new Rect (10010015080), "Video Ad")) {
            Debug.Log("video Ad");
            TnkAd.Plugin.Instance.prepareVideoAd("intro_video""testhandler");
        }

    }

}


public class MyTnkHandler : TnkAd.EventHandler {

    public override void onLoad() {
        Debug.Log ("##### TnkAd.Listener onLoad ");
        if (isOkToShow) {
            TnkAd.Plugin.Instance.showVideoAd("intro_video");
        } 

    }

}



[Video Ad APIs]

- TnkAd.Plugin - prepareVideoAd()

Method
  - void prepareVideoAd()
  - void prepareVideoAd(string logicName)
  - void prepareVideoAd(string logicName, string handlerName)

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

Parameters
Name Description
 logicName name of Display Logic. (See 5) Display Logic for detail)
handlerName name of EventHandler 

- TnkAd.Plugin - prepareVideoAdOnce()

Method
  - void prepareVideoAdOnce(string logicName, string handlerName)

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
 logicName name of Display Logic. (See 5) Display Logic for detail)
handlerName name of EventHandler 

- TnkAd.Plugin - showVideoAd()

Method
  - void showVideoAd()
  - void showVideoAd(string logicName)

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

- TnkAd.Plugin - hasVideoAd()

Method
  - bool hasVideoAd(string logicName)

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