View & Play Live Stream
Host your events virtually and see community interaction as it happens
Live streams and playback videos information are stored in AmityStream. These stream objects reside in AmityStreamRepository. To start working with stream, first, the app needs to initialize the repository.
1
val streamRepository = AmityVideoClient.newStreamRepository()
Copied!
Note : There is a limitation for the maximum number of concurrent live events. Reach out to us at community.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 AmityStream. The stream object contains essential data, for example, title and description.
1
streamRepository
2
.getStream(streamId)
3
.subscribe( {doOnNext} )
Copied!

Stream Status

Stream consists of many states. It can change from one state to another, depending on events and actions.
Amitystream.Status represents a stream status. The following enum cases describe all the possible statuses 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 process 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

AmityStreamRepository provides a convenient method getStreamsand also call setStatus(statuses: Array<Amitystream.Status>) to query live streams. We provide enums of stream status as AmityStream.Status
You can observe changes in a collection as per the defined statuses.
1
AmityVideoClient.newStreamRepository()
2
.getStreams()
3
.setStatus(arrayOf(AmityStream.Status.LIVE, AmityStream.Status.RECORDED))
4
.build()
5
.query()
6
.subscribe( {adapter.submitList(it)} )
Copied!

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 AmityWatcherData.Format.
1
AmityVideoClient.newStreamRepository()
2
.getStreamById(streamId)
3
.subscribe { stream ->
4
startStreaming(stream.getWatcherData()?
5
.getUrl(AmityWatcherData.Format.FLV))
6
}
Copied!
This function provides request/response API. The callback of this function returns a URL string.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 AmityWatcherData.Format.
1
AmityVideoClient.newStreamRepository()
2
.getStreamById(streamId)
3
.subscribe { stream ->
4
startStreaming(stream.getRecordings()[index]?
5
.getUrl(AmityRecordingData.Format.FLV))
6
}
Copied!
This function provides request/response API. The callback of this function returns a URL string.This object contains a full FLV, MP4 or M3U8 URL.

Recommended video player

We recommend using 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 using the DefaultDataSourceFactory.
1
val dataSourceFactory = DefaultDataSourceFactory(this, Util.getUserAgent(this, "Upstra"))
2
val videoSource = ProgressiveMediaSource.Factory(dataSourceFactory, DefaultExtractorsFactory())
3
.createMediaSource(Uri.parse(videoUrl))
4
5
exoplayer?.prepare(videoSource)
Copied!
For RTMP we highly recommend using the RtmpDataSourceFactory.
1
val dataSourceFactory = RtmpDataSourceFactory()
2
val videoSource = ProgressiveMediaSource.Factory(dataSourceFactory, DefaultExtractorsFactory())
3
.createMediaSource(Uri.parse(videoUrl))
4
5
exoplayer?.prepare(videoSource)
Copied!