Skip to the content.

Docs | Android

HTTP Connections

Since version 3.9.0.

On this page:

HTTP Client Selection

For playback purposes (downloading the media streams and communicating with the DRM server), PlayKit can use one of two HTTP clients:

From the app’s point of view, they both have the same functionality. However, OkHttp allows PlayKit more fine grained control over the connection, and it provides a private connection pool so that TCP connections can be reused (see below).

Selecting a client is done by using the class PKHttpClientManager in package com.kaltura.playkit.player. Calling the static PKHttpClientManager.setHttpProvider(String) method with "okhttp" as the parameter causes the player to use OkHttp for creating HTTP requests.

The default client is HttpURLConnection.

HTTP Connection Warmup

Depending on server configuration, a single TCP/TLS connection can remain open between HTTP requests. When the HTTP client makes a request to https://example.com/A, it first opens a TCP+TLS connection to example.com. When the request is done, it keeps the connection open for a predefined number of seconds/minutes. When it then requests https://example.com/B, it can reuse the connection from the first request, potentially saving a few seconds from the connection setup time.

With Connection Warmup, the application can ask PKHttpClientManager to open a connection to one or more hosts that it will later connect to; this will save time when starting to play.

After opionally selecting an http provider, the application calls PKHttpClientManager.warmUp(String...), passing a list of URLs:

Warmup works regadless of the http provider chosen, but with OkHttp the player has its own private pool so it won’t be cluttered by other services using HttpURLConnection, so the improvement is expected to be better.