Live Stream

Companies can now integrate live stream capabilities in no time. Our infrastructure can handle millions of viewers. Deliver the best viewing experience with adaptive bitrate delivery with live cloud video encoding. *Note : There is a limitation for the maximum concurrent live events. Please feel free to reach out to us for your use case via support email and we can determine if the current limit can be raised.

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.

// `client` is EkoClient that has been initiated during the setup
streamRepository = EkoStreamRepository(client: client)

Retrieve a stream object

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

  • repository.getStreamById(_:).

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

let streamProxy = streamRepository.getStreamById(streamId)
getStreamToken = streamProxy.observe { (proxy, error) in
// We have a stream object here.
let stream = proxy.object
print("Title: \(stream.title)")
print("Description: \(stream.streamDescription)")

Stream Status

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

EkoStreamStatus 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 .status.

// Print out the current status of a stream.

Retrieve streams collection

To query streams collection, first you need to create a EkoStreamCollectionQuery.

// Create query object.
let query = EkoStreamCollectionQuery()
// Specify statuses to include in the streams collection.

Then call .getStreamsCollection(from:) with the query object that you've created.

  • .getStreamsCollection(from: query)

This function returns the live collection of stream objects. To see the usage of live collection, please refer to EkoCollection.

// Here we get EkoCollection<EkoStream>
streamsCollection = streamRepository.getStreamsCollection(from: query)
// An example of streams collection usage,
// to observe the changes and update UI.
token = streamsCollection.observe { [weak self] collection, change, error in
// Any update will be notified here.
self?.updateUI(from: collection)

If your app needs stream collections in many parts of the app. We recommend to maintain only one collection for each query, in an application scope. And use it as a single source of truth.

App.liveStreamsCollections = streamRepository.getStreamsCollection(from: liveStreamQuery)
App.liveStreamsToken = App.liveStreamsCollection.observe { collection, change, error in
// Any update will be notified here.
App.updateDataSource(from: collection)

Play a live stream

To play a live stream, currently only RTMP protocol is supported, call

  • stream.watcherUrl

EkoLiveStreamURLInfo contains a full RTMP url, which most of RTMP players support. For some players that does not support the full url, this object contains enough data for custom RTMP url formatting.

if let urlInfo = stream.watcherUrl {
// play with the full url
// or for some players that require custom RTMP url formatting

Recommended RTMP players

RTMP is a low-latency video streaming protocol, that iOS does not support in its native video player. Therefore when working with RTMP, here are some open-source players that we recommend:

Play recorded videos

Live streams are recorded, and saved as files after the session ends. It would take some time for preparing recorded videos to be ready. You can observe the collection of stream that has recorded videos available, by calling

  • streamRepository.getRecordedStreams()

Each live stream session can contain multiple recorded videos. You can retrieve the array of EkoLiveVideoRecordingData that store all recording data, by calling

  • stream.recordingData

To get the actual url, you need to specify the file format by calling on a recorded item.

  • recordingItem.url(for: EkoLiveVideoRecordingFileFormat)

The following code shows an example of getting all the mp4 url of a stream instance.

// Print out all mp4 url for all recorded videos of `stream`.
for (index, dataItem) in stream.recordingData.enumerated() {
// Specify .MP4, to get the actual url in mp4 format.
if let url = dataItem.url(for: .MP4) {
print("Video \(index): \(url)")
} else {
print("Video \(index): url not found")

In contrast with RTMP live videos, you don't need 3rd party video player for the recorded videos. iOS native player already support playing mp4 file from the url given by API.

See also AVFoundation and AVKit.

Upstra Video Player

UpstraSDK includes UpstraVideoPlayerKit.framework, a basic RTMP player to support live video functionality.

This framework requires MobileVLCKit.framework as a dependency. You can download it from the link below.

Download MobileVLCKit.framework