Player public events

Listen to events from player:

You can listen to player events through the Notification Centre. SDK has a Notification.Name extension that contains all the possible events user can observe. There are some that recieve data through userInfo dictionary.

Available player events:

/// Notification for when the player is initialized.
public static let playerInitialized: Notification.Name

/// Notification for when the player has loaded the content.
public static let playerLoaded: Notification.Name

/// Notification for when the video is paused.
public static let videoPause: Notification.Name

/// Notification for when the video starts playing.
public static let videoPlay: Notification.Name

/// Notification for when the video is buffering.
public static let videoBuffering: Notification.Name

/// Notification for when the video playback ends.
public static let videoEnd: Notification.Name

/// Notification for when the next item in the playlist is played.
public static let playlistNext: Notification.Name

/// Notification for when the previous item in the playlist is played.
public static let playlistPrevious: Notification.Name

/// Notification for when the playlist ends.
public static let playlistEnd: Notification.Name

/// Notification for when the video is muted.
public static let videoMute: Notification.Name

/// Notification for when the video is unmuted.
public static let videoUnmute: Notification.Name

/// Notification for when the video starts autoplaying.
public static let videoAutoplay: Notification.Name

/// Notification for when the video url error happens.
public static let videoBadUrl: Notification.Name

/// Notification for when the player dismisses using `destroy()` player method.
public static let playerClose: Notification.Name

/// Notification for when playlist returns current index using `getCurrentIndex()` player method, returns Int.
public static let getCurrentIndex: Notification.Name

/// Notification for when users asks for video duration using `getDuration()` player method, returns String.
public static let getDuration: Notification.Name

/// Notification for when users asks for current player time using `getCurrentTime()` player method, returns CMTime.
public static let getCurrentTime: Notification.Name

/// Notification for when the playlist is retrieved.
public static let getPlaylist: Notification.Name

/// Notification for when the video source is retrieved.
public static let getSource: Notification.Name

/// Notification for when the video information is retrieved.
public static let getVideo: Notification.Name

/// Notification for when the volume level is retrieved.
public static let getVolume: Notification.Name

/// Notification for when a specific index in the playlist is played using `playByIndex()` player method.
public static let playByIndex: Notification.Name

/// Notification for when a video error occurs.
public static let videoError: Notification.Name

/// Notification for when a network error occurs.
public static let networkError: Notification.Name

/// Notification for when the video format is incorrect.
public static let videoFormatError: Notification.Name

/// Notification for when there is an error with video protection (e.g., DRM).
public static let videoProtectionError: Notification.Name

/// Notification for when a livestream video error occurs.
public static let videoLivestreamError: Notification.Name

/// Notification for when a video CMS-related error occurs.
public static let videoCmsError: Notification.Name

/// Notification for when the video is stopped.
public static let videoStop: Notification.Name

Available player advertising events:

/// Notification for when an ad is loaded.
public static let adLoaded: Notification.Name

/// Notification for when an ad request is made.
public static let adRequest: Notification.Name

/// Notification for when an ad impression is recorded.
public static let adImpression: Notification.Name

/// Notification for when an ad is completed.
public static let adCompleted: Notification.Name

/// Notification for when an ad is resumed.
public static let adResumed: Notification.Name

/// Notification for when an ad is skipped.
public static let adSkipped: Notification.Name

/// Notification for when content resumes after an ad.
public static let adContentResume: Notification.Name

/// Notification for when the first quartile of the ad is reached.
public static let adFirstQuartile: Notification.Name

/// Notification for when the midpoint of the ad is reached.
public static let adMidpoint: Notification.Name

/// Notification for when the third quartile of the ad is reached.
public static let adThirdQuartile: Notification.Name

/// Notification for when the ad starts.
public static let adStarted: Notification.Name

/// Notification for when the ad is paused.
public static let adPaused: Notification.Name

/// Notification for when the ad is tapped.
public static let adTapped: Notification.Name

/// Notification for when all ads are completed.
public static let allAdsCompleted: Notification.Name

/// Notification for when an ad break is ready.
public static let adBreakReady: Notification.Name

/// Notification for when an ad break starts.
public static let adBreakStarted: Notification.Name

/// Notification for when an ad break ends.
public static let adBreakEnded: Notification.Name

/// Notification for when the ad is buffering.
public static let adBuffering: Notification.Name

/// Notification for ad progress updates.
public static let adProgress: Notification.Name

/// Notification for when an ad period starts.
public static let adPeriodStarted: Notification.Name

/// Notification for when an ad period ends.
public static let adPeriodEnded: Notification.Name

/// Notification for when the ad is clicked.
public static let adClicked: Notification.Name

/// Notification for when content is paused for an ad request.
public static let adContentPauseRequested: Notification.Name

/// Notification for when an advertisement-related error occurs.
public static let adError: Notification.Name

/// Posted when an adbreak-related error occurs.
public static let adBreakFetchError: Notification.Name

How to use

In your UIViewController class add NotificationCenter observers with the Notification.Name from the available player event list with TargetVideoPlayer as the observer's object. Here is example of two observers setup to listen for .playerInitialized and .adImpression.

    private func setupNotificationObeservers() {
        NotificationCenter.default.addObserver(self, selector: #selector(handlePlayerInitializedNotification), name: .playerInitialized, object: player)
        NotificationCenter.default.addObserver(self, selector: #selector(handleAdImpressionNotification), name: .adImpression, object: player)
    }
    
    @objc private func handlePlayerInitializedNotification() {
        // Handle the playerInitialized notification
    }
    
    @objc private func handleAdImpressionNotification() {
        // Handle the adImpression notification
    }

Notifications that send data

Some notifications like .getCurrentIndex, .getDuration, .getCurrentTime. , etc. Contain data in their userInfo dictionary with key "playerEvents".

 NotificationCenter.default.addObserver(self, selector: #selector(handleDataNotification), name: .getVideo, object: player)

@objc private func handleDataNotification(_ notification: Notification) {
    if let currentVideoData = notification.userInfo?["playerEvents"] as? VideoData {
        // Handle the data recieved with notification
    }
}