# Discovery URLs

Before the player can play an OptiView Live channel, it sends a discovery request to find the stream details of that channel (such as its manifest URLs and token security settings). OptiView Live channels are served by one of three discovery API versions:

| API version | Channels                                          |
| ----------- | ------------------------------------------------- |
| V1 (legacy) | Channels created with the legacy THEOlive API.    |
| V2          | Distributions created with the OptiView Live API. |
| V3          | Distributions served by the newest discovery API. |

The player does not know in advance which API version serves your channel. If you do not configure a discovery URL, the player tries its built-in discovery URLs one by one, in this order:

1. V2
2. V1 (legacy)
3. V3

The player stops at the first discovery URL that returns the channel. If your channel is not served by V2, the earlier requests fail before the right one succeeds. These failed requests add a small delay before playback starts, and they show up as `404` responses in the network tab of your browser or in a network proxy. The `404` responses are expected and do not mean that playback failed.

## Why configure a discovery URL

When you configure the discovery URL that serves your channel, the player sends its first discovery request to that URL. This removes the failed requests and the extra startup delay.

Configured discovery URLs do not replace the built-in discovery URLs. The player tries them first, and continues with the built-in discovery URLs (V2, V1, V3) if the configured ones do not return the channel. A wrong discovery URL therefore costs one extra request, but it does not break playback.

On platforms that support both `discoveryUrl` and `discoveryUrls`, the player tries `discoveryUrl` first, then each URL of `discoveryUrls` in the order of the list, and then the built-in discovery URLs.

## Which discovery URL to use

The player derives the API version from the path of the discovery URL, so use the URL exactly as listed for your platform, including the trailing `/`. The URL for V1 channels is different on Web than on the other platforms.

| API version | Web                                             | Android, iOS, Roku                              |
| ----------- | ----------------------------------------------- | ----------------------------------------------- |
| V2          | `https://discovery.theo.live/v2/distributions/` | `https://discovery.theo.live/v2/distributions/` |
| V1 (legacy) | `https://discovery.theo.live/`                  | `https://discovery.theo.live/v2/publications/`  |
| V3          | `https://discovery.theo.live/v3/`               | `https://discovery.theo.live/v3/`               |

React Native and Flutter apps pass the discovery URL to the underlying Web, Android or iOS SDK, so the same rules apply per platform.

> **Find the API version of your channel**
>
> Play your channel without a discovery URL and open the network tab of your browser (or a network proxy for a native app). The discovery request that returns `200` shows the discovery URL that serves your channel. For example, a request to `https://discovery.theo.live/v2/distributions/<your-channel-id>` means that your channel is served by V2.

## Configure the discovery URL

Create a `THEOLiveConfig` with the discovery URL and pass it to the player configuration with `theoLive`. For example, for a channel served by V2:

```kotlin
import com.theoplayer.android.api.THEOplayerConfig
import com.theoplayer.android.api.theolive.THEOLiveConfig

val theoLiveConfig = THEOLiveConfig.Builder()
    .discoveryUrl("https://discovery.theo.live/v2/distributions/")
    .build()

val playerConfig = THEOplayerConfig.Builder()
    .license("your-license")
    .theoLive(theoLiveConfig)
    .build()
```

Android supports one configured discovery URL. If the channel is not found there, the player continues with the built-in discovery URLs.

The player derives the API version from the URL path:

* A URL that contains `/v3/` is a V3 discovery URL.
* A URL that contains `/v2/distributions/` is a V2 discovery URL.
* Any other URL, including `https://discovery.theo.live/v2/publications/`, is a V1 discovery URL.

Because of these rules, `https://discovery.theo.live/v2/` without `distributions/` is treated as a V1 discovery URL on Android.

## Configuration reference

[`THEOLiveConfig`](https://optiview.dolby.com/docs/theoplayer/v11/api-reference/android/com/theoplayer/android/api/theolive/THEOLiveConfig) has the following properties. You can set them with the methods of `THEOLiveConfig.Builder`, or as named arguments of the `THEOLiveConfig.Builder` constructor.

| Property            | Type      | Description                                                                                                                      |
| ------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------- |
| `discoveryUrl`      | `String?` | A discovery URL that the player tries before the built-in discovery URLs. Defaults to `null`.                                    |
| `analyticsDisabled` | `Boolean` | Whether OptiView Live analytics is disabled. Defaults to `false`.                                                                |
| `externalSessionId` | `String?` | Deprecated. An ID used to report usage analytics. Use `THEOplayerConfig.cmcd.externalSessionId` instead, which takes precedence. |

The default discovery order V2, V1, V3 applies from THEOplayer 11.13.0. Earlier versions try V1 first.
