Skip to main content
Skip table of contents

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.

CODE
public class OTVNetworkAnalytics: NSObject {
	public var adaptiveStreaming: AdaptiveStreaming
	public var networkUsage: NetworkUsage
	public var contentServer: ContentServer
}
Network errors and http error code and message.
CODE
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.
CPP
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
  - Note: This function will make a seperate request for the Master playlist to return all the availableBitrates. This request is only done once you call this           function and only on the first time you call it for that contnet. Every subsiquent call on the same content does not requst the playlist again. 
 */
  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

  /**
   Returns the number of times the bitrate has switched.
   - Returns: the number of times the bitrate has switched.
  */
  func bitrateSwitches() -> Int

  /**
   Returns the number of times the bitrate has switched to a lower bitrate.
   - Returns: the number of times the bitrate has switched to a lower bitrate.
  */
  func bitrateDowngrade() -> Int

  /**
   Returns the Video and Audio track’s average bit rate, in bits per second.
   - Returns: the Video and Audio track’s average bit rate, in bits per second.
  */
  func averageBitrate() -> Int

  /**
   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 averageVideoBitrate() -> Int

  /**
   Returns the audio track’s average bit rate, in bits per second.
   - Returns: the  audio track’s average bit rate, in bits per second.
  */
  func averageAudioBitrate() -> Int
 
}
Network analytics related to network usage.
CPP
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

  /**
   Returns the number of media read requests from the server to this client
   - Returns: The number of media read requests from the server to this client or -1 if unknown
  */
  func numberOfMediaRequests() -> Int

  /**
   Returns the accumulated duration, in seconds, of active network transfer of bytes
   - Returns: the accumulated duration, in seconds, of active network transfer of bytes or -1 if unknown
  */
  func transferDuration() -> TimeInterval
  /**
   Returns the total number of times that downloading the segments took too long.
   - Returns: the total number of times that downloading the segments took too long or -1 if unknown
  */
  func downloadsOverdue() -> Int
}
Network analytics related to the content server.
CPP
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?

  /**
   Returns a count of changes to the server address over the last uninterrupted period of playback.
   - Returns: the number of server address changes or -1 if unknown
  */
  func numberOfServerAddressChanges() -> Int
}
Notification and all event type.
CODE
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.
CODE
NotificationCenter.default.addObserver(self,
                                       selector: #selector(handleNetworkAnalyticsNotification(notificaition:)),
                                       name: .OTVNetworkAnalyticsNotification,
                                       object: nil)

func handleNetworkAnalyticsN
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
					}
				}
			}
		}
	}
}     


JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.