Skip to content

Parameter setSegmentAcceptor

Description

The setSegmentAcceptor method in TeleportConfiguration.Builder allows you to define a function for identifying requests for downloading video segments. This is necessary for the Teleport SDK to intercept and process only those requests that relate to media segments intended for peer-to-peer delivery.

Default Behavior

By default, the Teleport SDK identifies segments by their extensions: .ts, .mp4, .m4s, .m4v, .m4a, .vtt.

When is it necessary?

You will need to define your own setSegmentAcceptor function in the following cases:

  • Non-standard URLs: If your media server uses specific or non-standard URL addresses for video segments that do not match standard extensions.
  • Excluding Init Segments: If your streaming protocol involves "init" segments (initialization segments) that should not be processed by Teleport. In this case, the function should be configured to exclude such segments.

Function Requirements

  • The function must accept a Uri and return a Boolean (true if the URL is a video segment).
  • Called on a background thread.

Example Usage

kotlin
TeleportConfiguration.Builder("YOUR_API_KEY")
        .setSegmentAcceptor { uri: Uri ->
            // Example: identifies a segment by the presence of ".mp4" in the path and excludes "init" segments
            uri.path?.contains(".mp4") ?: false && !uri.path?.contains("init")
        }
        .build()

In this example, the setSegmentAcceptor function will consider any URL containing ".mp4" but not "init" in the path as a segment.