NAV
     

Development Guide

Apple TV API provides stream urls and ad break information (interstitials) for Live and VOD content.

The following steps are sufficient for a typical use case:

Add the API script

API script must be added prior to using API methods.

<script type="application/javascript" src="anvtveapi.min.js"></script>

Initialize the AnvTveAPI instance

Initialize the AnvTveAPI instance using accessKey, secret key and primary config.

var tve = new AnvTveApi(
        "YOUR_ACCESS_KEY",
        "YOUR_SECRET_KEY",
        { // Primary Config and override config is provided here
            video: "VIDEO_ID", // primary config (required)
            geoZip: "GEO_ZIP", // remaining is override config (optionally used for overriding remote configuration)
            accessControl: {
                requestor: "ADOBE_PASS_REQUESTOR_ID",
                resourceId: "ADOBE_PASS_RESOURCE_ID"
            },
            plugins: {
                freewheel: {
                    videoAssetId: "OVERRIDE_ASSET_ID"
                }
            },
            adBreakDetail: true // override value for getting the individual ad detail as opposed to ad break information
        },
        false // logging
);

Get the remote configuration

The API makes use of a remote config to access predefined parameters and service URLs. API user is supposed to provide success and error callbacks for this async step.

tve.getConfig(onConfigSuccess, onConfigFailure);

Get video stream urls and ad break information

In this step, the API user can pass in the newly available information such as the viewer’s provider ID, service zip and maximum allowed rating. And finally success and error callbacks are set.

function onConfigSuccess(result){
    tve.getVideoInfo(
        { // dynamic info (which may be available after successful authN and authZ) is provided here
            mvpd: "MVPD_ID",
            homeZip: "HOME_ZIP",
            maxRating: "MAX_RATING"
        },  onVideoInfoSuccess, onVideoInfoFailure);
}

The response will include the playback urls and ad breaks if available as shown in the sample section on the side:

 {
     urls: [
       {
           breaks: "...", // available when adBreakDetail flag is set to true in primary config 
           primary: "...",
           backup: "...",
           interstitials: "...", 
           sessionId: "..."    
       }
    ]
 }

Reference Guide

Constructor

AnvTveApi(accessKey, secretKey, config, enableLogging)

Provides services for getting remote config and video information Parameters:

Name Type Description
accessKey string Your access key provided by Anvato
secretKey string Your secret key provided by Anvato
config object config object with mandatory “video” entry and optional override information used for overriding remote config
debug boolean used for turned on debug logs
var tve = new AnvTveApi(
        "YOUR_ACCESS_KEY",
        "YOUR_SECRET_KEY",
        {
            video: "VIDEO_ID", // primary config (required)
            geoZip: "GEO_ZIP", // remaining is override config (optional)
            accessControl: {
                requestor: "ADOBE_PASS_REQUESTOR_ID",
                resourceId: "ADOBE_PASS_RESOURCE_ID"
            },
            plugins: {
                freewheel: {
                    videoAssetId: "OVERRIDE_VIDEO_ASSET_ID"
                }
            }
        },
        false // logging
);

Public Methods

getConfig(successCallback, errorCallback)

Gets the remote configuration

Parameters:

Name Type Description
successCallback function success callback (with an argument to see the remote config)
errorCallback function error callback
tve.getConfig(onConfigSuccess, onConfigFailure);

getVideoInfo(dynamicInfo, successCallback, errorCallback)

Gets the video info

Parameters:

Name Type Description
dynamicInfo object newly available info such as mvpd, maxRating and service zip is entered
successCallback function success callback
errorCallback function error callback
tve.getVideoInfo(
    { // dynamic info (which may be available after successful authN and authZ) is provided here
        mvpd: "MVPD_ID",
        homeZip: "HOME_ZIP",
        maxRating: "MAX_RATING"
    },  onVideoInfoSuccess, onVideoInfoFailure);

Public Properties

isConfigSet

Name Type Description
isConfigSet boolean Indicates if the remote config is successfully set and getVideoInfo can proceed without issues
function playVideo(){
    if (tve.isConfigSet) {
        console.warn("Config already loaded, proceeding with getVideoInfo");
        onConfigSuccess();
    } else {
        tve.getConfig(onConfigSuccess, onConfigFailure);
    }
}