Native API

Native API

The following article provides a reference to the collection of methods through which you can initialize and configure your player. After the Setup stage, where you initialize the player, you have access to the API Methods and Events through which you can interact with the player.

Setup

For an easier setup, we recommend that you place the Connatix player into a container view with the wanted aspect ratio and size.

You also need to provide the player type (Elements or Playspace) and a config object.

Swift

When using IOS:

override func viewDidLoad() {
        super.viewDidLoad()
         
        //Config object example, only containing a playerID
        var elementsConfig = ConnatixConfig("4eb27585-bf9c-485b-9686-255eff35f8ed")
 
        //Example with Elements player type
        var connatixPlayer = ConnatixPlayerSDK(frame: .zero, playerType: .Elements, config: elementsConfig)
        connatixPlayer(EventType.play, false)
        containerView.insertSubview(connatixPlayer, at: 0)
 
        containerView.addConstraint(NSLayoutConstraint(item: connatixPlayer!, attribute: .top, relatedBy: .equal, toItem: containerView, attribute: .top, multiplier: 1, constant: 0))
        containerView.addConstraint(NSLayoutConstraint(item: connatixPlayer!, attribute: .bottom, relatedBy: .equal, toItem: containerView, attribute: .bottom, multiplier: 1, constant: 0))
        containerView.addConstraint(NSLayoutConstraint(item: connatixPlayer!, attribute: .right, relatedBy: .equal, toItem: containerView, attribute: .right, multiplier: 1, constant: 0))
        containerView.addConstraint(NSLayoutConstraint(item: connatixPlayer!, attribute: .left, relatedBy: .equal, toItem: containerView, attribute: .left, multiplier: 1, constant: 0))
}

 

Kotlin

The Kotlin setup also needs a container, and you can easily add it to the XML layout of the project.

When using Android:

//New Elements player instance
override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
 
        var connatixPlayer = ConnatixPlayerSDK(context:this, attrs:null, defStyleAttr:0, delegate:this)
 
        var params : LinearLayout.LayoutParams = LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT
        )
        connatixPlayer.layoutParams = params
        sdkContainerView.addView(connatixPlayer)
 
        //Config object example, only containing a playerID
        val elementsConfig = PlayerConfig("cd6bde64-da62-4f4d-bb78-79ec535f1727")
 
        //Example with Elements player type
        connatixPlayer.setupPlayer(playerType: PlayerType.Elements, config: elementsConfig)
        connatixPlayer?.listenFor(EventType.volumeChanged,true)
}

 

Functions

play()

This function sets the player state to "play".

 playerSDK.play() 

 

pause()

This function sets the player state to "pause".

 playerSDK.pause() 

 

setVolume(volume: CGFloat)

This function sets the volume of the player to the specified value, a float between 0 and 1.

 playerSDK.setVolume(0.4) 

 

getVideoDetails()

This function returns the details of the video currently playing:

  • id string
  • title  string
  • desciption string
  • duration string
  • keywords array of strings
 let videoDetails = playerSDK.getVideDetails() 

 

getVideoCurrentPositions()

This function returns a Float representing the position of the video currently playing in seconds.

 let videoPosition = playerSDK.getVideoCurrentPositions() 

 

getVideoDuration()

This function returns a Float representing the total duration of the video currently playing in seconds.

 let videoDuration = playerSDK.getVideoDuration() 

 

toggleFullscreen()

This function toggles the fullscreen state of the player.

 playerSDK.listenFor(EventType.pause, false) 

 

Events

How to Register

listenFor(event: EventType, once:Bool)

This method registers to a single event. When used, it can apply as a one-time listener, or for as long as the player is alive.

 playerSDK.listenFor(EventType.pause, false) 

 

listenForMore(events: [ EventType ] )

This method registers to an array of events.

 let eventArray = [EventType.play, EventType.pause, EventType.volumeChanged]
playerSDK.listenForMore(_ events: [EventType]) 

 

listenForAllEvents()

This method registers to all available events.

 playerSDK.listenForAllEvents() 

 

remove(event: EventType)

This method removes the listener for specified event.

 playerSDK.remove(EventType.pause) 

 

removeAllEvents()

This method removes all event listeners.

 playerSDK.removeAllEvents() 

 

EventType

Init

ready

This event fires when the experience is ready.

 

Advertising

adClick 

This event fires when an ad was clicked.

 

adPlay

This event fires when an ad starts playing.

 

adPause

This event fires when an ad is paused.

 

adImpression

This event fires on ad impression and returns the ad's duration in seconds  along with its ID.

 

adCompleted25

This event fires when 25% of the ad played.

 

adCompleted50

This event fires when 50% of the ad played.

 

adCompleted75

This event fires when 75% of the ad played.

 

adCompleted100

This event fires when 100% of the ad played.

 

adSkipped

This event fires when the skip ad button is clicked.

 

adStopped

This event fires when the ad stopped.

 

adCompanion

This event fires when an ad companion was provided and will return the following info:

adCompanion
attributes description possible values type
companionClickURL Branding type.   String
width Width of the companion banner ad.   Int
height Height of the companion banner ad.   Int
creativeURL URL of the creative.   String Url
type Companion ad displaying methods.
  • Static (0)
  • iFrame (1)
Enum
trackingPixelsArray Array of tracking pixels.   Array

 

Content

videoStarted

This event fires when a new video is started.

 

videoComplete25

This event fires when 25% of the content has played.

 

videoComplete50

This event fires when 50% of the content has played.

 

videoComplete75

This event fires when 75% of the content has played.

 

videoComplete100

This event fires when 100% of the content has played.

 

Viewability

isViewable

This event returns a boolean which is true if the player is 50% in view and in an active tab, and false if it’s below 50% or in an inactive tab.

 

Playback

play

This event fires when a new video is started.

 

pause

This event fires when a new video is paused.

 

Volume

volumeChanged

This event fires when the volume of the player has changed. It contains the new value.

 

Resize

fullscreenChanged

This event fires when player’s fullscreen state changes and returns the new value as a boolean.

 

Controls

qualityChanged

This event fires when the player’s quality has changed and returns the new quality value.

 

subtitlesVisibilityChanged

This event fires when the video subtitles are turned on or off, and returns the current state.

 

UI Interaction

playerClicked

This event fires when the player was clicked in the click URL area. This event will only be fired when the video is playing.

 

Errors

setupError

This event fires when running the init script fails, or when the targeting rules are not met. When this happens, an error message is generated.

 

playError

This event fires when playing the video fails. When this happens, an error message is generated.

 

adError

This event fires when the ad fails.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

Please sign in to leave a comment.