AdPlayerTag APIs - iOS

Obtaining AdPlayerTag Instance

Instances of AdPlayerTag can be obtained in one of two ways:

  1. Obtaining them right after the initialization (this is the earliest point at which the instance is available)

AdPlayer.initializePublisher(publisher) { result in switch result { case .success(let tag): // tag instance available here case .failure(let error): // tag initialization failed } }

2. Requesting them from AdPlayer

AdPlayer.getTagWhenReady(tagId: tagId) { result in switch result { case .success(let tag): // tag instance available here case .failure(let error): // tag initialization failed } }

3. In order to perform an action only if a tag is ready now and otherwise skip it, you may request the tag now if present using the following API

guard let tag = AdPlayer.getTagNowOrNil(tagId: tagId) else { // no tag }

A common use for this API is when launching interstitial ads.

Events

As the player is playing its content, the AdPlayerTag emits relevant events describing the process.

To receive the events you should assign an observer that confirms to the AdPlayerTagEventsObserver protocol by one of the following methods:

Add an observer as part of the tag initialization process

Or add an observer to an instance of AdPlayerTag after obtaining it using method 2 of the previous section

The emitted events are:

Event class

Event type

Description

Event class

Event type

Description

AdPlayerEventGeneric

AdPlayerEventType.fullScreenRequested

Called when the user requested full screen.

AdPlayerEventGeneric

AdPlayerEventType.inventory

Called when the player is initialized.

AdPlayerEventGeneric

AdPlayerEventType.adLoaded

Indicates the first time an ad sources triggered the AdLoaded event.

AdPlayerEventGeneric

AdPlayerEventType.adImpression

Called when there is a video impression.

AdPlayerEventGeneric

AdPlayerEventType.adVideoFirstQuartile

Called when the ad reached 25% of the ad video.

AdPlayerEventGeneric

AdPlayerEventType.adVideoMidpoint

Called when the ad reached 50% of the ad video.

AdPlayerEventGeneric

AdPlayerEventType.adVideoThirdQuartile

Called when the ad reached 75% of the ad video.

AdPlayerEventGeneric

AdPlayerEventType.adVideoCompleted

Called when the ad is completed.

AdPlayerEventGeneric

AdPlayerEventType.adClickThrough

Called when the ad is clicked on.

AdPlayerEventGeneric

AdPlayerEventType.adSkipped

Called when an ad is skipped.

AdPlayerEventGeneric

AdPlayerEventType.adSkippableStateChanged

Called when the ad skip button becomes available.

AdPlayerEventGeneric

AdPlayerEventType.closed

Called when the close button is clicked.

AdPlayerEventGeneric

AdPlayerEventType.adPaused

Called when the ad is paused.

AdPlayerEventGeneric

AdPlayerEventType.adPlaying

Called when the ad starts playing or resumed.

AdPlayerEventGeneric

AdPlayerEventType.contentPaused

Called when the content video is paused.

AdPlayerEventGeneric

AdPlayerEventType.contentPlaying

Called when the content video resume playing.

AdPlayerEventVolume

AdPlayerEventType.adVolumeChange

Called when the ad volume is changed. Contains the new volume level in the AdPlayerEventVolume.volume parameter. Casting is required to access the parameter.

AdPlayerEventVolume

AdPlayerEventType.contentVolumeChange

Called when the content volume is changed. Contains the new volume level in the AdPlayerEventVolume.volume parameter. Casting is required to access the parameter.

AdPlayerEventGeneric

AdPlayerEventType.contentVideoStart

Content started playing.

AdPlayerEventGeneric

AdPlayerEventType.contentVideoFirstQuartile

Called when the content reached 25%.

AdPlayerEventGeneric

AdPlayerEventType.contentVideoMidpoint

Called when the content reached 50%.

AdPlayerEventGeneric

AdPlayerEventType.contentVideoThirdQuartile

Called when the content reached 75%.

AdPlayerEventGeneric

AdPlayerEventType.contentVideoComplete

Called when the content is completed.

AdPlayerEventError

AdPlayerEventType.adError

Called by the player every time it finish running 1 + vastRetry waterfall runs without impression. An (optional) error message can be found at AdPlayerEventError.message. Casting is required to access the parameter.

AdPlayerEventGeneric

AdPlayerEventType.adErrorLimit

Called also whenever the player decides that it should stop running, for example when maxImp or maxRun is reached, to indicate the player is stopping calls for ads.

AdPlayerEventError

AdPlayerEventType.error

An error has occurred. An (optional) error message can be found at AdPlayerEventError.message. Casting is required to access the parameter.

Controls

The AdPlayerTag allows you to control the player programmatically.

  • To pause the player, call AdPlayerTag.pause()

  • To resume playback, call AdPlayerTag.resume()

  • AdPlayerTag.skipAd() skips an ad if one is playing and skippable

  • AdPlayerTag.playingState.state == .playing: detects whether or not the player is playing

Configurations

While most of the configurations are available on the dashboard, the AdPlayerTag provides some configurations to the player that can be changed in code. The configurations should be provided as part of the initialization process.

Some of the configurations also appear as assignable fields on the AdPlayerTag and can be changed at any time while others can be provided only at initialization and cannot be changed later.