Broadcast Live Stream

To broadcast a live stream video, we provide a convenient broadcaster tool called EkoStreamBroadcaster. We now only support 16:9 video ratio with the following resolution representing by the enum EkoStreamBroadcastResolution:

  • .SD_480P indicates a video with resolution 480x854 and video bitrate 1216 kpbs

  • .HD_720P indicates a video with resolution 720x1280 and video bitrate 2496 kpbs

  • .FHD_1080P indicates a video with resolution 1080x1920 and video bitrate 4992 kpbs

Setup

You simply need to include this dependency to your project in build.gradle in the application level.

implementation 'com.github.EkoCommunications.EkoMessagingSDKAndroid:eko-video-publisher:x.y.z'

Inside your Application class, in the application initialisation process, you need to register the video publisher sdk to the core sdk by calling.

  @Override
  open fun onCreate() {
        super.onCreate()
        EkoStreamPublisherClient.setup(EkoClient.getConfiguration())
    }

We highly recommend to use Android's ConstraintLayout to construct our EkoCameraView Since we only support 16:9 video ratio, ConstratntLayout will ensure that the view will be drawn in the correct width and height.

Authorize the required permissions

EkoStreamBroadcaster requires the following permissions to work properly.

As per the required parameter by the aforementioned object to provide EkoCameraView , you will need to define the view in your Activity or Fragment layout by :

  1. Camera access

  2. Microphone access

Before using EkoStreamBroadcaster, please make sure these permissions are granted.

See here the steps to ask for the permissions.

Create an EkoStreamBroadCaster Object

In order to create the object, we also provide a EkoStreamBroadCaster.Builder class to create and configure this object easily. It requires EkoCameraView as a parameter and EkoStreamBroadcasterConfig as a configurable value which will be explained in the following section.

val broadcaster = EkoStreamBroadcaster.Builder(eko_camera)
        .setConfiguration(broadcasterConfig)
        .build()

Prepare a configuration

For configuration, we provide a EkoStreamBroadcasterConfiguration.Builder to construct the configuration conveniently. As we have mentioned above, We support SD_480P, HD_720P and, FHD_1080P resolutions. Orientations are relying on Android Configuration class, you may either choose Configuration.ORIENTATION_PORTRAIT or Configuration.ORIENTATION_LANDSCAPE .

val configuration = EkoStreamBroadcasterConfiguration.Builder()
        .setOrientation(Configuration.ORIENTATION_PORTRAIT)
        .setResolution(EkoBroadcastResolution.HD_720P)
        .build()

Setup a layout

As per the required parameter by the aforementioned object to provide EkoCameraView , you need to define the view in your Activity or Fragment layout by :

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.ekoapp.sdk.publisher.EkoCameraView
        android:id="@+id/eko_camera"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintDimensionRatio="H,9:16"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.5">
    </com.ekoapp.sdk.publisher.EkoCameraView>

</androidx.constraintlayout.widget.ConstraintLayout>

We highly recommend to use Android's ConstraintLayout to construct our EkoCameraView Since we only support 16:9 video ratio, ConstratntLayout ensures that the view will be drawn in the correct width and height.

Preview the video

To begin previewing the camera input call

broadcaster.startPreview()

Start live stream session

To begin broadcasting live stream call

broadcaster.startPublish(title: String, description: String)

Stop live stream session

To stop broadcasting live stream call

broadcaster.stopPublish()

Switch camera position

By default, the broadcaster will use the back camera. However you can switch camera position anytime by calling.

broadcaster.switchCamera()

Observe a broadcasting state

To observe the status of a broadcast, we provide a function (flow) to observe any status changes and return as EkoStreamBroadcasterState . The possible statuses are :

  • .IDLEindicates a status of stream in an idle state.

  • .CONNECTINGindicates a status of stream that it's connecting to a rtmp server.

  • .CONNECTEDindicates a status of stream that it's connected to a rtmp server.

  • .DISNNECTED(e:Exception)indicates a status of stream that it's disconnected to a rtmp server. We also provide an error information through an exception.

broadcaster.stateFlowable
        .subscribe { status ->
                when (status) {
                is EkoStreamBroadcasterState.CONNECTED { showConnected() }
                is EkoStreamBroadcasterState.CONNECTING { showConnecting() }
                is EkoStreamBroadcasterState.DISCONNECTED { exception -> showDisconnected(e)}
                }
 }

Last updated