View & Play Live Stream

Host your events virtually and see community interaction as it happens

Live streams and playback videos information are stored in EkoStream. This stream objects reside in EkoStreamRepository. To start working with stream, first the app need to intialize the repository.

val streamRepository = EkoClient.newStreamRepository()

*Note : There is a limitation for the maximum concurrent live events. Please feel free to reach out to us at developer@amity.co with your use-case and we will determine if the current limit can be raised.

Retrieve a stream object

Each stream object has a unique identifier. To retrieve a single stream object.

This function returns a flowable of EkoStream. The stream object contains essential data, for example, title and description.

streamRepository
       .getStreamById(streamId)
       .subscribe( {doOnNext} )

Stream Status

Stream consists of many states. It can change from one state to another, depending on events and actions.

Ekostream.Status represents a stream status. The following enum cases describe all the possible status of a stream.

  • .IDLE indicates "a stream that has generated but no actions have been taken."

  • .LIVE indicates "a stream is currently being broadcasted."

  • .ENDED indicates "a stream has ended broadcasting and in the progess of transforming to a recorded stream."

  • .RECORDED indicates "a stream has ended broadcasting and has been transformed to a recorded stream."

You can check the status of a stream by calling stream.getStatus().

Retrieve a stream collection

EkoStreamRepository provides a convenient method getStreamCollection and also call setStatus(statuses: Array<Ekostream.Status>) to query live streams. We provide enums of stream status as Ekostream.Status

You can observe changes in a collection as per the defined statuses.

  EkoClient.newStreamRepository()
         .getStreamCollection()
         .setStatus(arrayOf(EkoStream.Status.LIVE, EkoStream.Status.RECORDED))
         .build()
         .query()
         .subscribe( {adapter.submitList(it)} )

Play a live stream

To play a live stream, currently FLV, RTMP and HLS protocol are supported by calling getWatcherData.getUrl() inside the stream object. The parameter accepts streamId and enum of EkoWatcherData.Format.

  EkoClient.newStreamRepository()
                .getStreamById(streamId)
                .subscribe { stream -> 
                    startStreaming(stream.getWatcherData()?
                            .getUrl(EkoWatcherData.Format.FLV))
                }

This function provides request/response API. The callback of this function returns string of the url.This object contains a full FLV, RTMP or HLS url.

Play a recorded stream

To play a recorded stream, currently FLV, MP4 and M3U8 protocol are supported by calling getRecordings()[index] inside the stream object. The parameter accepts streamId and enum of EkoWatcherData.Format.

  EkoClient.newStreamRepository()
                .getStreamById(streamId)
                .subscribe { stream -> 
                    startStreaming(stream.getRecordings()[index]?
                            .getUrl(EkoRecordingData.Format.FLV))
                }

This function provides request/response API. The callback of this function returns string of the url.This object contains a full FLV, MP4 or M3U8 url.

We recommend to use ExoPlayer from Google. ExoPlayer supports features not currently supported by Android’s MediaPlayer API, including DASH and SmoothStreaming adaptive playbacks. Unlike the MediaPlayer API, ExoPlayer is easy to customize and extend.

For FLV we highly recommend to use DefaultDataSourceFactory

val dataSourceFactory = DefaultDataSourceFactory(this,  Util.getUserAgent(this, "Upstra"))
val videoSource = ProgressiveMediaSource.Factory(dataSourceFactory, DefaultExtractorsFactory())
                .createMediaSource(Uri.parse(videoUrl))
                
exoplayer?.prepare(videoSource)

For RTMP we highly recommend to use the RtmpDataSourceFactory

val dataSourceFactory = RtmpDataSourceFactory()
val videoSource = ProgressiveMediaSource.Factory(dataSourceFactory, DefaultExtractorsFactory())
                .createMediaSource(Uri.parse(videoUrl))
                
exoplayer?.prepare(videoSource)

Last updated