API Reference

This article acts a reference to the API configuration options AdPlayer.Pro supports.

Supported Methods

 

Method Usage Description
pauseAd()
AdPlayerPro.pauseAd()
The video player calls pauseAd() to prompt the ad unit to pause ad display.

The ad unit responds by suspending any audio, animation or video and then sending the AdPaused event.

resumeAd()
AdPlayerPro.resumeAd()
Following a call to pauseAd(), the video player calls resumeAd() to continue ad playback.

The ad unit responds by resuming playback and sending the AdPlaying event to confirm.

stopAd()
AdPlayerPro.stopAd()
The video player calls stopAd() when it will no longer display the ad or needs to cancel the ad unit.

The ad unit responds by closing the ad, cleaning up its resources and then sending the AdStopped event.

skipAd()
AdPlayerPro.skipAd()
Configures skip controls that the video player may implement.

The video player calls skipAd() when a user activates a skip control implemented by the video player.

When called, the ad unit responds by closing the ad, cleaning up its resources and sending the AdSkipped event.

setAdVolume(value)
AdPlayerPro.setAdVolume(value)
Configures the volume option.

Supported values: from 0 to 1

Example: 1 = 100% Volume, 0.5 = 50% Volume.

getAdVolume()
AdPlayerPro.getAdVolume()
Returns details regarding the current ad playback volume.
resizeAd(int width, int height)
AdPlayerPro.resizeAd(int width, int height)
Provides an option to get player resized
getAdWidth()
AdPlayerPro.getAdWidth()
Returns the Width value of the currently playing ad (player).
getAdHeight()
AdPlayerPro.getAdHeight()
Returns the Height value of the currently playing ad (player).
getAdRemainingTime()
AdPlayerPro.getAdRemainingTime()
The video player may use the adRemainingTime property to update player UI during ad playback, such as displaying a playback counter or other ad duration indicator.

The adRemainingTime property is provided in seconds and is relative to the total duration value, provided in the adDuration property.

getAdDuration()
AdPlayerPro.getAdDuration()
Returns the total ad duration in seconds.
getAdSkippableState()
AdPlayerPro().getAdSkippableState()
The video player calls getAdSkippableState() to сheck the current ad unit [skippability] status, i.e. whether it’s possible to skip the ad, or not.

When called, the ad unit responds by returning the “true” or “false” value, depending on whether the AdSkippableStateChange event has been sent or not, accordingly.

 

Supported Events

 

Event Usage Description
AdLoaded
AdPlayerPro.on('AdLoaded', function(){});
As soon as ad is ready for display, the ad dispatches the AdLoaded event.
AdStarted
AdPlayerPro.on('AdStarted', function(){});
The AdStarted event is sent by the ad unit to notify the video player that the ad is displaying.
AdVideoStart
AdPlayerPro.on('AdVideoStart', function(){});
These five events are sent by the ad unit to notify the video player of the ad unit’s video progress and are used in VAST under the same event names.
AdVideoFirstQuartile
AdPlayerPro.on('AdVideoFirstQuartile', function(){});
AdVideoMidpoint
AdPlayerPro.on('AdVideoMidpoint', function(){});
AdVideoThirdQuartile
AdPlayerPro.on('AdVideoThirdQuartile', function(){});
AdVideoComplete
AdPlayerPro.on('AdVideoComplete', function(){});
AdStopped
AdPlayerPro.on('AdStopped', function(){});
The AdStopped event is sent by the ad unit to notify the video player that the ad has stopped displaying and all ad resources have been cleaned up.

This event is only for responding the stopAd() method call made by the video player.

AdSkipped
AdPlayerPro.on('AdSkipped', function(){});
The AdSkipped event is sent by the ad unit to notify the video player that the ad has been skipped, stopped displaying and all ad resources have been cleaned up.
AdPaused
AdPlayerPro.on('AdPaused', function(){});
The AdPaused event is sent in response to the pauseAd() method call to confirm that the ad is either paused or stopped.

Sending AdPaused indicates that the ad has stopped all audio and any animation in progress.

AdPlaying
AdPlayerPro.on('AdPlaying', function(){});
The AdPaused and AdPlaying events are sent in response to the pauseAd() and resumeAd() method calls to confirm that the ad has either paused or is playing.

Sending AdPlaying indicates that the ad unit has resumed playback from the point at which it was paused.

AdError
AdPlayerPro.on('AdError', function(message, error){});
The AdError event is sent when the ad unit has experienced a fatal error.

Before the ad unit sends AdError it must clean up all resources and cancel any pending ad playback.

AdVolumeChange
AdPlayerPro.on('AdVolumeChange', function(){});
AdVolumeChange event is dispatched to notify the video player of the change.
AdSkippableStateChange
AdPlayerPro.on('AdSkippableStateChange', function(){});
The AdSkippableStateChange event is sent at the point when the ad unit becomes skippable, i.e. when it becomes possible to skip the ad.
AdClickThru
AdPlayerPro.on('AdClickThru', function(){});
The AdClickThru event is sent when an ad click-through, i.e. a click on the ad, occurs.

 

Code Examples

Example 1: 

Describing all logic (methods, events processing – just in a row):

<script src="https://cdn.stat-rock.com/player/demo.js"></script>
<script>(function(){
    document.write("<div id='NQnZsTCfCv1TVOZeJTaLZjM9zzUJ240XenGSYnKSUhpgalBwQaIT'></div>");
    AdPlayerPro('NQnZsTCfCv1TVOZeJTaLZjM9zzUJ240XenGSYnKSUhpgalBwQaIT').setup({
    "muted": true,
    "autoStart": true,
    "width": "480",
    "height": "360",
    "soundByHover": true,
    "type": "inPage",
    "advertising": {
         "tag": [
            {
                "url": "https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&amp;iu=/124319096/external/ad_rule_samples&amp;ciu_szs=300x250&amp;ad_rule=1&amp;impl=s&amp;gdfp_req=1&amp;env=vp&amp;output=vmap&amp;unviewed_position_start=1&amp;cust_params=deployment%3Ddevsite%26sample_ar%3Dpreonly&amp;cmsid=496&amp;vid=short_onecue&amp;correlator",
                "client": "googima",
                "type": "url",
                "rotation": true,
                "replay": true
            }
        ],
        "requestTimeout": 10000,
        "creativeTimeout": 5000,
        "bestTimeout": 2000,
        "position": "BR",
        "barColor": "#2e95ff",
        "skipOffset": 3,
        "sticky": true,
        "stickyWidth": "",
        "stickyHeight": "",
        "rotation": 2,
        "watermarkLink": "https://watermark_link.com",
        "watermarkIcon": "https://watermark_icon.com\"",
        "sequential": true
    },
    "tapToUnmute": true
    }).on('AdStarted', function() {alert('started')});
})();
</script>

Example 2: 

You can also specify a player variable and then call all available events methods. For example: variable.{method_name} etc.
<script src="https://cdn.stat-rock.com/player/demo.js"></script>
<script>(function(){
    document.write("<div id='NQnZsTCfCv1TVOZeJTaLZjM9zzUJ240XenGSYnKSUhpgalBwQaIT'></div>");
    var adPlayerPro = AdPlayerPro('NQnZsTCfCv1TVOZeJTaLZjM9zzUJ240XenGSYnKSUhpgalBwQaIT').setup({
    "muted": true,
    "autoStart": true,
    "width": "480",
    "height": "360",
    "soundByHover": true,
    "type": "inPage",
    "advertising": {
        "tag": [
            {
                "url": "https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/ad_rule_samples&ciu_szs=300x250&ad_rule=1&impl=s&gdfp_req=1&env=vp&output=vmap&unviewed_position_start=1&cust_params=deployment%3Ddevsite%26sample_ar%3Dpreonly&cmsid=496&vid=short_onecue&correlator",
                "client": "googima",
                "type": "url",
                "rotation": true,
                "replay": true
            }
        ],
        "requestTimeout": 10000,
        "creativeTimeout": 5000,
        "bestTimeout": 2000,
        "position": "BR",
        "barColor": "#2e95ff",
        "skipOffset": 3,
        "sticky": true,
        "stickyWidth": "",
        "stickyHeight": "",
        "rotation": 2,
        "watermarkLink": "https://watermark_link.com",
        "watermarkIcon": "https://watermark_icon.com",
        "sequential": true
    },
    "tapToUnmute": true
});
//describing the logic
adPlayerPro.on('AdStarted', function(){alert('ad has been started...')});
adPlayerPro.on('AdVideoMidpoint', function(){adPlayerPro.pauseAd()});
//etc
})();
</script>