Skip to content

Parameter setSegmentResolver

Description

The setSegmentResolver method in TeleportConfiguration.Builder allows you to define a function for filtering segment requests and selecting their download source. This function returns one of the sources defined by the SegmentSource class, determining whether the segment will be processed by the Teleport SDK or downloaded directly from the CDN.

SegmentSource Class

The SegmentSource class defines possible segment download sources:

  • SegmentSource.CDN: The segment will be downloaded directly from the CDN, bypassing the Teleport protocol. Such segments are not included in Teleport statistics.
  • SegmentSource.TELEPORT: The segment will be processed by the Teleport SDK. Ultimately, it will be included in statistics, regardless of whether it was downloaded from the peer-to-peer network or from the CDN (if peers could not provide the segment).

When is it necessary?

Use setSegmentResolver if you need flexible control over which segments should pass through the Teleport PDN and which should go directly through the CDN. This can be useful for specific content types (e.g., audio tracks that do not require P2P optimization) or to bypass issues with certain segments.

Function Requirements

  • The function must accept Uri (segment URL), SegmentType (segment type), and SegmentQuality (segment quality).
  • The function must return one of the values of the SegmentSource class.
  • Called on a background thread.

Call Order

This function is called after setSegmentAcceptor and setSegmentTypeGetter. If setSegmentAcceptor previously returned false for a segment, then setSegmentResolver will not be called for that segment.

Example Usage

kotlin
TeleportConfiguration.Builder("YOUR_API_KEY")
        .setSegmentResolver { url: Uri, segmentType: SegmentType, segmentQuality: SegmentQuality ->
            // Example: all audio segments are downloaded directly from CDN, others - via Teleport
            if (segmentType == SegmentType.AUDIO) {
                SegmentSource.CDN
            } else {
                SegmentSource.TELEPORT
            }
        }
        .build()

In this example, all audio segments will be downloaded directly from the CDN and will not be included in Teleport statistics, while all other segment types will be processed by the Teleport SDK and included in statistics.