Lumen help

CDN Load Balancer for Android and Android TV

Introduction

Project Setup

                repositories {
    maven {
        url 'https://sdk.streamroot.io/android'
    }
}
            
                implementation 'io.streamroot.lumen.delivery.client:mesh-sdk:22.03.2'
            

Integrate Lumen SDK

                <meta-data
    android:name="io.streamroot.lumen.delivery.client.DeliveryClientKey"
    android:value="DCKey" />
            
                class SRApplication: MultiDexApplication() {

    override fun onCreate() {
        super.onCreate()
        LumenDeliveryClient.initializeApp(this, "DCKey")
    }
}

            
                android:name=".SRApplication"
            
                private fun initDeliveryClient(newPlayer: SimpleExoPlayer) =
        LumenDeliveryClient.orchestratorBuilder(applicationContext)
                .playerInteractor(ExoPlayerInteractor(newPlayer))
                .options {
                    contentId(<string>)
                    orchestratorProperty(<string>)
                    deliveryClientKey(<string>)
                    logLevel(<string>)
                 }
                .build(mStreamUrl)
            
                deliveryClient.start()
            
                 val finalUrl = lumenDeliveryClient.localUrl()
            
                 @SuppressLint("SwitchIntDef")
private fun buildMediaSource(uri: Uri): MediaSource {
    val defaultDataSourceFactory =
        DefaultHttpDataSourceFactory(
                Util.getUserAgent(applicationContext, "StreamrootQA"),
                DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
                DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS,
                true
        )

    return when (Util.inferContentType(uri)) {
        C.TYPE_HLS -> HlsMediaSource.Factory(defaultDataSourceFactory)
            //.setDrmSessionManager()
            .createMediaSource(uri)
        C.TYPE_DASH -> DashMediaSource.Factory(
            DefaultDashChunkSource.Factory(
                defaultDataSourceFactory
            ), defaultDataSourceFactory
        )
            //.setDrmSessionManager()
            .createMediaSource(uri)
        else -> {
            throw IllegalStateException("Unsupported type for url: $uri")
        }
    }
}

            
                deliveryClient.stop()
            
                import com.google.android.exoplayer2.ExoPlaybackException
import com.google.android.exoplayer2.ExoPlayer
import com.google.android.exoplayer2.PlaybackParameters
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.source.TrackGroupArray
import com.google.android.exoplayer2.trackselection.TrackSelectionArray
import io.streamroot.lumen.delivery.client.core.*

class ExoPlayerInteractor(player: ExoPlayer) : LumenPlayerInteractorBase(), Player.EventListener {

    init { player.addListener(this) }

    override fun onSeekProcessed() {
        super.playerStateChange(LumenVideoPlaybackState.SEEKING)
    }

    override fun onTracksChanged(trackGroups: TrackGroupArray, trackSelections: TrackSelectionArray) {
        super.playerTrackSwitch()
    }

    override fun onPlayerError(error: ExoPlaybackException) {
        super.playerError()
    }

    override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) {
        when (playbackState) {
            Player.STATE_IDLE -> {
                super.playerStateChange(LumenVideoPlaybackState.IDLE)
            }
            Player.STATE_BUFFERING -> {
                super.playerStateChange(LumenVideoPlaybackState.REBUFFERING)
            }
            Player.STATE_READY -> {
                super.playerStateChange(if (playWhenReady) LumenVideoPlaybackState.PLAYING else LumenVideoPlaybackState.PAUSED)
            }
            Player.STATE_ENDED -> {
                super.playerStateChange(LumenVideoPlaybackState.ENDED)
            }
        }
    }
}
            
                <?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <application
        ...
        android:usesCleartextTraffic="true">
        ...
    </application>
</manifest>
            
  • Add 'localhost' in the allowed domains in a new network_security_config.xml file
                <?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">localhost</domain>
    </domain-config>
</network-security-config>
            
  • And add this file in the AndroidManifest.xmlnetwork_security_config.xml file
                <?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <application
        ...
        android:networkSecurityConfig="@xml/network_security_config">
        ...
    </application>
</manifest>
            

Explore CDN services