Skip to main content
Skip table of contents

OkHttpClient Override

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

The CONNECT SDK Player for Android needs a network connection to fetch the stream's assets, namely the media files and manifests, using the Android device's default network settings. Sometimes, you may wish to override these settings to accommodate parameters specific to the streaming services, for example, HTTP protocols supported, cache, cookies or DNS resolution. The SDK provides the means to use your own HTTP implementation for such scenarios. The Player uses its own instance OkHttpClient for all of its media-fetching activities and provides an API for overriding the Player's implementation with your own. The overriding method is in the OTVVideoView class:

JAVA
void setOkHttpClient(OkHttpClient xClient)

The API for overriding OkHttpClient applies to fetching manifests and media files only. The override does not affect other network activities (such as DRM messages).

Implementation

The dns-resolver example code, delivered with the Player package, demonstrates how to create and override an OkHttpClient instance. In this example, the new client overrides the DNS resolution method getDNS(URL host).

The example code provides only a skeleton for resolving domain names privately using DNS over HTTPS (DoH). It is only for demonstration and does not perform a genuine name resolution.

The example code makes use of a factory class named OkHttpClientProvider, which can then instantiate an OkHttpClient object through getOkHttpClient(), with a DNS overriding method. You must implement your own OkHttpClient version.

The example code MainActivity class instigates playback, similar to other examples. However, in this example, after the OTVVideoView is created, but before it is set with the stream's URL, the player view is assigned a new OkHttpClient instance through the setOkHttpClient(OkHttpClient xClient) method.

JavaScript errors detected

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

If this problem persists, please contact our support.