Skip to main content
Version: 0.x.x

RTMP Livestream - Android

RTMP is a popular protocol for live streaming video content from a VideoSDK to platforms such as YouTube, Twitch, Facebook, and others.

By providing the platform-specific stream key and stream URL, the VideoSDK can connect to the platform's RTMP server and transmit the live video stream.

VideoSDK allows you to livestream your meeting to platform which support RTMP ingestion just by providing the platform-specific stream key and stream URL, we can connect to the platform's RTMP server and transmit the live video stream.

VideoSDK also allows you to configure the livestream layouts in numerous ways like by simply setting different prebuilt layouts in the configuration or by providing your own custom template to do the livestream according to your layout choice.

This guide will provide an overview of how to implement start and stop RTMP Livestreaming.

startLivestream()​

startLivestream() method, accesible from the Meeting class, is used to initiate the RTMP livestream. This method accepts the following two parameters:

  • 1. outputs: This parameter accepts a list of LivestreamOutput objects which contains the RTMP url and streamKey of the platforms you want to start the livestream.

  • 2. config: This parameter will define how the livestream layout should look like. You can pass null for default layout.

val config = JSONObject()

// Layout Configuration
val layout = JSONObject()
JsonUtils.jsonPut(layout, "type", "GRID") // "SPOTLIGHT" | "SIDEBAR", Default : "GRID"
JsonUtils.jsonPut(layout, "priority", "SPEAKER") // "PIN", Default : "SPEAKER"
JsonUtils.jsonPut(layout, "gridSize", 4) // MAX : 4
JsonUtils.jsonPut(config, "layout", layout)

// Theme of livestream layout
JsonUtils.jsonPut(config, "theme", "DARK") // "LIGHT" | "DEFAULT"

val outputs: MutableList<LivestreamOutput> = ArrayList()
outputs.add(LivestreamOutput(RTMP_URL, RTMP_STREAM_KEY))

liveStream!!.startLivestream(outputs,config)

stopLivestream()​

  • stopLivestream() is used to stop the meeting livestream which can be accessed from the Meeting class.

Example​

// keep track of livestream status
val liveStream = false

findViewById<View>(R.id.btnLiveStream).setOnClickListener { view: View? ->
if (!liveStream) {
val config = JSONObject()
val layout = JSONObject()
JsonUtils.jsonPut(layout, "type", "GRID")
JsonUtils.jsonPut(layout, "priority", "SPEAKER")
JsonUtils.jsonPut(layout, "gridSize", 4)
JsonUtils.jsonPut(config, "layout", layout)
JsonUtils.jsonPut(config, "theme", "DARK")

val outputs: MutableList<LivestreamOutput> = ArrayList()
outputs.add(LivestreamOutput(RTMP_URL, RTMP_STREAM_KEY))

// Start LiveStream
liveStream!!.startLivestream(outputs,config)
} else {
// Stop LiveStream
liveStream!!.stopLivestream()
}
}

Event associated with Livestream​

  • onLivestreamStateChanged - Whenever meeting livestream state changes, then onLivestreamStateChanged event will trigger.
private val meetingEventListener: MeetingEventListener = object : MeetingEventListener() {
override fun onLivestreamStateChanged(livestreamState: String?) {
when (livestreamState) {
"LIVESTREAM_STARTING" -> Log.d( "LivestreamStateChanged",
"Meeting livestream is starting"
)
"LIVESTREAM_STARTED" -> Log.d( "LivestreamStateChanged",
"Meeting livestream is started"
)
"LIVESTREAM_STOPPING" -> Log.d("LivestreamStateChanged",
"Meeting livestream is stopping"
)
"LIVESTREAM_STOPPED" -> Log.d("LivestreamStateChanged",
"Meeting livestream is stopped"
)
}
}
}

override fun onCreate(savedInstanceState: Bundle?) {
//...

// add listener to meeting
liveStream!!.addEventListener(meetingEventListener)
}

API Reference​

The API references for all the methods utilised in this guide are provided below.

Got a Question? Ask us on discord