CONNECT Player SDK 5 for Apple (FPS)
5.14.x 5.13.x 5.12.x 5.11.x 5.10.x 5.9.x 5.8.x 5.7.x 5.6.x 5.5.x 5.4.x 5.3.x 5.2.x 5.1.x 5.0.x
5.14.x 5.13.x 5.12.x 5.11.x 5.10.x 5.9.x 5.8.x 5.7.x 5.6.x 5.5.x 5.4.x 5.3.x 5.2.x 5.1.x 5.0.x

Network statistics

To test this feature and view the example code, please see the  Apple (FPS) SDK 5 Example Code Quick Start guide.

The CONNECT Player SDK provides classes and interfaces enabling you to access statistics concerning the player and network.

public class OTVNetworkAnalytics: NSObject {
	public var adaptiveStreaming: AdaptiveStreaming
	public var networkUsage: NetworkUsage
	public var contentServer: ContentServer
}

Network errors and http error code and message: 

public class OTVNetworkAnalytics: NSObject {
	// Error code, -1001 indicates other network error; 400 indicates http error, check httpError for status code 
  	public internal(set) var error: Int
	// HTTP response status code when gets http error
  	public internal(set) var httpError: Int {
	// HTTP error message
  	public internal(set) var httpErrorMessage: String?
}


Network analytics related to adaptive streaming

public protocol AdaptiveStreaming {
  /**
   Returns an array of bitrates available in the playlist
   - Returns: an array of bitrates available in the playlist, or nil if unknown
   */
  func availableBitrates() -> [Int]?
  /**
   Returns the bitrate from the playlist that has been selected for playback, in bits per second
   - Returns: the bitrate from the playlist that has been selected for playback, or 0 if unknown
   */
  func selectedBitrate() -> Double
}

Network analytics related to network usage

public protocol NetworkUsage {
  /**
   Returns the number of bytes downloaded so far
   - Returns: the number of bytes downloaded so far
   */
  func bytesDownloaded() -> Int64

  /**
   Returns the empirical throughput, in bits per second, across all media downloaded
   - Returns: the throughput, in bits per second
   */
  func downloadBitrate() -> Double

  /**
   Returns the video track’s average bit rate, in bits per second
   - Returns: the video track’s average bit rate, in bits per second
   */
  func downloadBitrateAverage() -> Double
}

Network analytics related to the content server

public protocol ContentServer {
  /**
   Returns the IP address of the content server
   - Returns: the IP address of the content server for the last segment, or nil if unknown
   */
  func finalIPAddress() -> String?

  /**
   Returns the URL of the selected playlist, after any redirects
   - Returns: the URL of the selected playlist, or nil if unknown
   */
  func finalURL() -> String?

  /**
   Returns the original URL of the stream
   - Returns: the original URL of the stream, or nil if unknown
   */
  func url() -> String?
}

Notification and all event type

public static let OTVNetworkAnalyticsNotification = Notification.Name("OTVNetworkAnalyticsNotification")
public enum Event: Int {
    case selectedBitrateChanged = 0
    case availableBitratesChanged = 1
    case urlChanged = 2
    case errorChanged = 3
  }

Observe the OTVNetworkAnalyticsNotification and get the event

NotificationCenter.default.addObserver(self,
                                       selector: #selector(handleNetworkAnalyticsNotification(notificaition:)),
                                       name: .OTVNetworkAnalyticsNotification,
                                       object: nil)

func handleNetworkAnalyticsNotification(notificaition: NSNotification) {
	if let otvNetworkNotificationType = notificaition.object as? OTVNetworkAnalytics.Event {
		switch otvNetworkNotificationType {
			case .selectedBitrateChanged:
				if let selectedBitrate = otvplayer?.networkAnalytics?.adaptiveStreaming.selectedBitrate() {
					// Handle selectedBitrate
				}
			case .availableBitratesChanged:
				if let availableBitrates = otvplayer?.networkAnalytics?.adaptiveStreaming.availableBitrates() {
					// Handle availableBitrates
				}	
			case .urlChanged:
				if let url = otvplayer?.networkAnalytics?.contentServer.url() {
					// Handle url
				}
			case .errorChanged:
				if let error = otvplayer?.networkAnalytics?.error {
					if error = -1001 {
						// Other network error
					} else if error == 400, 
						let httpError = otvplayer?.networkAnalytics?.httpError,
						let httpErrorMessage = otvplayer?.networkAnalytics?.httpErrorMessage {
						// Handle http error code and http error message
					}
				}
			}
		}
	}
}