Parameter setTimeslotParser
Description
The setTimeslotParser method in TeleportConfiguration.Builder allows you to define a function for extracting the segment number (or timeslot) from its URL. This number can be a sequential number (e.g., 0, 1, 2, ...), a timestamp (in seconds or milliseconds), or any other numbering scheme that increments for consecutive segments.
Importance of timeslotParser
The timeslotParser function is not mandatory, but it is highly recommended for use. It allows the Teleport SDK to more accurately match peers with each other, as it begins to take into account the relative timeslots of peers. This significantly increases the efficiency and quality of peer-to-peer delivery.
When is it necessary?
Use setTimeslotParser if the URLs of your video segments contain information about the sequential number or timestamp of the segment.
Important
If the URL generation scheme for segments does not provide sequential numbering, you should not set timeslotParser. In this case, the default implementation will be used, always returning 0. Incorrect use of this function can lead to reduced peering efficiency.
Function Requirements
- The function must accept a
Uriand return aLong(segment number or timeslot).
Example Usage
TeleportConfiguration.Builder("YOUR_API_KEY")
.setTimeslotParser { uri: Uri ->
// Example: extracting the segment number from the URL path
val pathSegments = uri.pathSegments
if (pathSegments.isNotEmpty()) {
pathSegments.last().substringBefore(".").toLongOrNull() ?: 0L
} else {
0L
}
}
.build()In this example, timeslotParser attempts to extract a numeric identifier from the last path segment of the URL.