Skip to main content

Stream Concurrency

Stream concurrency is a personalization library that facilitates concurrency checks while starting or continuing playback and aborts if the check fails. The library enforces this by keeping track of the number of unique active streaming devices for a user. This helps keep the concurrent streams in check for any particular user and abort existing or disallow new playback if the number of concurrent streams exceeds the allowed limit. The library relies on the PlatformAuthorizer and the PlatformClient instances to identify the particular user and device.

Manual enforcement

You can manually maintain the stream concurrency limits using StreamConcurrencyService.

// endpoint of the stream concurrency microservice. will be provided while on-boarding onto Quickplay platform. 
// the backslash at the end should be included.
val streamConcurrencyEndPointURL = "https://example.com/"
val streamConcurrencyService: StreamConcurrencyService =
StreamConcurrencyFactory.createStreamConcurrencyService(
streamConcurrencyEndPointURL,
platformAuthorizer // the relevant PlatformAuthorizer instance
)


// Put a Stream for a device
val putStreamResult = streamConcurrencyService.putStream(platformClient) // PlatformClient instance
when (putStreamResult) {
is Result.Success -> {
logger.info { "putStream succeeded for device ID ${platformClient.id}"}
}

is Result.Failure -> {
logger.error { "putStream failed with error ${result.value}" }
TODO("Handle putStream call failure as required")
}
}

// Delete the stream for a device
val deleteStreamResult = streamConcurrencyService.deleteStream(platformClient) // PlatformClient instance
when (deleteStreamResult) {
is Result.Success -> {
logger.info { "Stream deleted for device ID ${platformClient.id}"}
}

is Result.Failure -> {
logger.error { "deleteStream failed with error ${result.value}" }
TODO("Handle deleteStream call failure as required")
}
}

Automatic enforcement

Create StreamConcurrencyConfiguration

StreamConcurrencyConfiguration encapsulates all the necessary information required to automate Stream Concurrency.

Property NameTypeDefault ValueDescription
streamConcurrencyEndPointURLStringNAThe endpoint of StreamConcurrency microservice.
platformClientPlatformClientNAThe PlatformClient instance corresponding to the playback.
streamConcurrencySyncIntervalMsLong5000LThe preferred time interval, in milliseconds, to periodically sync the stream's status (that is, trigger a StreamConcurrencyService.putStream call). The stream status is updated every 5 seconds by default.
streamConcurrencyMaxAllowedFailuresInt5The maximum number of consecutive failed StreamConcurrencyService.putStream calls (network or infrastructure issues) that are allowed to happen before the content's playback is terminated
reserveStreamOnPlayerLoadBooleanfalseThe flag to reserve a stream before the playback starts.
// endpoint of the stream concurrency microservice. will be provided while on-boarding onto Quickplay platform. 
// the backslash at the end should be included.
val streamConcurrencyEndPointURL = "https://example.com/"

val streamConcurrencySyncIntervalMs = 15_000L // Pass preferred value

val streamConcurrencyConfiguration = StreamConcurrencyManager.StreamConcurrencyConfiguration(
streamConcurrencyEndPointURL,
platformClient, // the relevant PlatformClient instance
streamConcurrencySyncIntervalMs, // Optional, default value is 5000L
)

Create StreamConcurrencyManager

StreamConcurrencyManager takes care of automating all the API calls to maintain and delete the status of a stream. You must create a new StreamConcurrencyManager before the start of any new playback to maintain accuracy.

StreamConcurrencyFactory.createStreamConcurrencyManager(
player, // the relevant ComposablePlayer instance
platformAuthorizer, // the relevant PlatformAuthorizer instance
streamConcurrencyConfiguration
)
note

You can convert a normal Player into a ComposablePlayer using the composablePlayerWith function.

Once you create StreamConcurrencyManager, it ensures that the status of the stream is updated periodically and also on applicable player state changes. It also takes care of deleting the stream when you stop the player.