Kotlin Extensions

Kotlin Extensions

The SDK bundle includes a few optional Kotlin extensions. You can use these extensions by adding the castlabs-sdk-extensions module as a dependency to your build.gradle.

To use these extensions you can import them like this:

import com.castlabs.android.sdkextensions.*

ConfigExtensions

These extensions allow you to create a PlayerConfig object getting rid of some boilerplate code required by the Builder pattern.

PlayerConfig.Builder("http://domain.com/manifest.mpd").build {
    autoPlay(true)
    userID("userId")
    bufferConfig {
        minPlaybackStart(5, TimeUnit.SECONDS)
        bufferSizeBytes(20_000_000)
    }
    liveConfig {
        liveEdgeLatencyMs(5000)
    }
    abrConfig {
        minDurationForQualityIncrease(10, TimeUnit.SECONDS)
    }
    networkConfig {
        manifestConnectionTimeoutMs(5000)
        segmentsConnectionTimeoutMs(3000)
    }
}

ControllerExtensions

The SDK offers one extension for the PlayerController. The open extension masks the Builder creation thus making it cleaner to configure the Player.

Keep in mind that it is always mandatory to set the content url.

playerController.open {
    contentUrl("http://domain.com/manifest.mpd")
    autoPlay(true)
    userID("userId")
    bufferConfig {
        minPlaybackStart(5, TimeUnit.SECONDS)
        bufferSizeBytes(20_000_000)
    }
    liveConfig {
        liveEdgeLatencyMs(5000)
    }
    abrConfig {
        minDurationForQualityIncrease(10, TimeUnit.SECONDS)
    }
    networkConfig {
        manifestConnectionTimeoutMs(5000)
        segmentsConnectionTimeoutMs(3000)
    }
}
Previous topic: Example Projects
Next topic: Upgrade Guides