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:
- HttpURLConnection - the system’s built-in client.
- OkHttp - an Open Source client developed by Square.
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:
- One URL per host: don’t specify both
https://example.com/A
andhttps://example.com/B
, since both of those URLs are handled by the same host, they will share the connection anyway - The URL must be valid, and should request a well-known static file on the server. A good example of such file is
favicon.ico
(https://example.com/favicon.ico
). Another example iscrossdomain.xml
. Please make sure those files exist on the particular server before adding them to the warmup list. Using requests that resolve to existing static files means the request will be handled by the CDN and not the backend.
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.