Lumen help

CDN Load Balancer plugin for ExoPlayer on Android

Plugin Installation

                dependencyResolutionManagement {
    repositories {
        maven { url 'https://sdk.streamroot.io/android' }
    }
}
            
                // It is good practice to lock dependencies version
def dc_version = '22.09.1'
def exo_version = '2-18'
def plugin_patch = 0
implementation "io.streamroot.lumen.delivery.client:orchestrator-plugin-exoplayer-$exo_version:$dc_version.$plugin_patch"
            

Configuration

                -keep class io.streamroot.** { *; }
-dontwarn io.streamroot.lumen.**
            
                <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
            
                <?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
</network-security-config>
            
                <manifest ...>
    <application
        ...
        android:usesCleartextTraffic="true"
        android:networkSecurityConfig="@xml/network_security_config">
    </application>
</manifest>
            

Set the delivery client key

                <meta-data
android:name="io.streamroot.lumen.delivery.client.DeliveryClientKey"
android:value="<delivery-client-key>"
/>
            

Code Integration

                class Application: MultiDexApplication() {

    override fun onCreate() {
        super.onCreate()
        /* If you could not add your Delivery Client Key in your AndroidManifest.xml
         * Call instead: LumenDeliveryClient.initializeApp(this, "<delivery-client-key>")
         */
        LumenDeliveryClient.initializeApp(this)
        ...
    }
}
            
                android:name=".Application"
            
                val builder = LumenDeliveryClientPlugin.Builder(this, manifestUrl)
            
                // Pre created
val exoPlayerBuilder = ExoPlayer.Builder(this)
val pluginBuilder = LumenDeliveryClientPlugin.Builder(this, manifestUrl).exoPlayerBuilder(exoPlayerBuilder)

// Using hook
val pluginBuilder = LumenDeliveryClientPlugin.Builder(this, manifestUrl).exoPlayerBuilder { exoPlayerBuilder ->  
    // Work with exoPlayerBuilder
}
            
                // Pre created
val loadControlBuilder = DefaultLoadControl.Builder()
val pluginBuilder = LumenDeliveryClientPlugin.Builder(this, manifestUrl).loadControlBuilder(loadControlBuilder)

// Hook
val pluginBuilder = LumenDeliveryClientPlugin.Builder(this, manifestUrl).loadControlBuilder { defaultLoadControlBuilder ->
    // Work with defaultLoadControlBuilder
}
            
                val pluginBuilder = LumenDeliveryClientPlugin.Builder(this, manifestUrl).bandwidthMeterCustomFactory { exoPlayerBuilder ->
    ExoPlayerBandwidthMeter(this, exoPlayerBuilder)
}
            
                LumenDeliveryClientPlugin.Builder(this, manifestUrl).orchestratorOptions {
    /*
    * Set Orchestrator property
    *
    * param: String
    */
    orchestratorProperty("MY_PROPERTY")
    /*
    * Set the Delivery Client Key
    * Is only required if it was not set in AndroidManifest.xml
    * Will override the AndroidManifest.xml DeliveryClientKey
    *
    * param: String
    */
    deliveryClientKey("<delivery-client-key>")
    /*
    * Set the log level
    * See the "How to investigate?" to know more
    *
    * param: LumenLogLevel
    */
    logLevel(LumenLogLeven.INFO)
    /*
    * Set latency in seconds
    *
    * param: Int
    */
    latency(25)
    /*
    * Set a proxy server
    * Allows the use of a proxy server in the middle
    * Format is host:port
    *
    * params: String
    */
    proxyServer("MY_PROXY_HOST:PORT")
}
            
                // If you have no plugin config or orchestrator config steps
val plugin = LumenDeliveryClientPlugin.Builder(this, manifestUrl).build()

// Plugin configuration + orchestratorOptions (empty)
val plugin = LumenDeliveryClientPlugin.Builder(this, manifestUrl).loadControlBuilder{}.orchestratorOptions{}.build()
            
                plugin.start()
val finalUrl = plugin.finalUri
            
                val mediaItem = MediaItem.fromUri(finalUrl)
            
                // Calling stop will finish ongoing tasks and release all resources used
plugin.stop()
            

Compact integration example

                LumenDeliveryClientPlugin.Builder(this, manifestUrl).orchestratorOptions {
    logLevel(LumenLogLevel.INFO)
}.start().apply {
    plugin = this // plugin is stocked in the activity as a field

    bindings.playerView.player = exoPlayer
    showStatsView(this) // see the StatsView section to understand this

    exoPlayer.playWhenReady = true
    exoPlayer.addMediaItem(MediaItem.fromUri(Uri.parse(finalUri)))
    exoPlayer.repeatMode = Player.REPEAT_MODE_ALL
    exoPlayer.prepare()
}
            

Troubleshooting

                LumenDeliveryClient.setLogLevel(LumenLogLevel.INFO)
LumenDeliveryClient.initializeApp(this)
            
                LumenDeliveryClientPlugin.Builder(this, manifestUrl).orchestratorOptions {
    logLevel(LumenLogLevel.INFO)
}