All Products
Search
Document Center

HTTPDNS:Best practices for Android HTTPDNS and ExoPlayer

Last Updated:Dec 03, 2025

The Android SDK integration process document describes the complete process of importing and configuring the Android SDK, parsing IP addresses, applying settings to your network library, and verifying the integration. This topic describes how to integrate HTTPDNS with ExoPlayer using OkHttp.

1. Background

Media3 is the solution recommended by Google for creating audio and video experiences. It provides a simple architecture that enables powerful customization, reliability, and optimization based on device features to eliminate the complexity caused by fragmentation, allowing Android applications to display rich audiovisual experiences. ExoPlayer is the default implementation of the Player interface in Media3.

ExoPlayer uses DataSource to read resource data from a URI. By default, DefaultHttpDataSource reads resources from the network and uses HttpURLConnection to handle network requests. ExoPlayer also provides the OkHttpDataSource extension, which uses the OkHttp network library to handle network requests.

OkHttp exposes an interface for custom DNS services, which lets you easily integrate HTTPDNS. For this reason, OkHttpDataSource is the recommended data source.

2. Adding the OkHttp extension SDK

You need to select an appropriate OkHttp extension SDK based on the version of ExoPlayer that you use.

  • If you are using the ExoPlayer version under androidx media, you need to add the following dependency:

implementation "androidx.media3:media3-datasource-okhttp:x.x.x"
Note

The version of the OkHttp extension SDK must be consistent with the version of the ExoPlayer SDK.

If you are using ExoPlayer2, you need to add the following dependency:

implementation "com.google.android.exoplayer:extension-okhttp:x.x.x"
Note

The version of the OkHttp extension SDK must be consistent with the version of the ExoPlayer SDK.

3. Using the OkHttp extension SDK

When you initialize ExoPlayer, use the OkHttp extension SDK.

Note

The code of the OkHttp extension SDKs used for the two ExoPlayer versions is the same.

val player: ExoPlayer = ExoPlayer.Builder(context)
    .setMediaSourceFactory(
        DefaultMediaSourceFactory(
            OkHttpDataSource.Factory(
                Call.Factory { 
                    // Replace the value with the OkHttpClient instance in your project.
                    request -> client.newCall(request) 
                })
        )
    )
    .build()
ExoPlayer player = new ExoPlayer.Builder(context)
        .setMediaSourceFactory(new DefaultMediaSourceFactory(new OkHttpDataSource.Factory(new Call.Factory() {
                    @NonNull
                    @Override
                    public Call newCall(@NonNull Request request) {
                        // Replace the value with the OkHttpClient instance in your project.
                        return client.newCall(request);
                    }
                })))
        .build();

4. Using HTTPDNS with OkHttp

Finally, integrate HTTPDNS into the OkHttp network library. For specific integration steps, see Best practices for Android HTTPDNS+OkHttp.