All Products
Search
Document Center

HTTPDNS:Best practices for Android HTTPDNS and ExoPlayer

Last Updated:Jun 17, 2026

After you complete the Android SDK integration process, including SDK import, configuration, IP address parsing, network library setup, and verification, you can integrate HTTPDNS with ExoPlayer by using OkHttp as described in this topic.

1. Background

Media3 is the Google-recommended solution for building audio and video experiences on Android. It offers a simple, customizable architecture that optimizes playback based on device features and reduces fragmentation complexity. ExoPlayer is the default Player implementation in Media3.

ExoPlayer uses DataSource to read media data from a URI. By default, DefaultHttpDataSource handles network requests through HttpURLConnection. ExoPlayer also provides an OkHttpDataSource extension that uses OkHttp for network requests instead.

Because OkHttp exposes an interface for custom DNS services, HTTPDNS can be integrated directly. This makes OkHttpDataSource the recommended data source.

2. Adding the OkHttp extension SDK

Select the OkHttp extension SDK that matches your ExoPlayer version.

  • If you use the ExoPlayer version under androidx media, 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 use ExoPlayer2, 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

Initialize ExoPlayer with the OkHttp extension SDK as shown below.

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 OkHttp. For detailed steps, see Best practices for Android HTTPDNS+OkHttp.