Skip to main content
Version: 3.x.x

Go Live On Social Media - Android

This feature allows a participant to broadcast a meeting on social media platforms such as Facebook or YouTube. This guide shows how a participant can start and stop broadcasting a meeting.

  1. Start LiveStream - By using startLivestream() function, a participant can start broadcasting meeting on various platforms by providing url and stream keys as an argument. The second argument, config, sets the layout, orientation and quality. It has no default value: pass null to use the defaults.
  2. Stop LiveStream - By using stopLivestream() function, a participant can stop broadcasting on all platforms.

Start And Stop Live Stream​

Both methods are suspend functions. Call them from a coroutine, such as lifecycleScope.launch (from androidx.lifecycle:lifecycle-runtime-ktx), and catch the VideoSDKException they throw when a call is refused or fails.

private val YOUTUBE_RTMP_URL: String? = null
private val YOUTUBE_RTMP_STREAM_KEY: String? = null

// set from onLivestreamStateChanged below
private var livestreaming = false

//
findViewById<View>(R.id.btnLivestream).setOnClickListener {
lifecycleScope.launch {
try {
if (!livestreaming) {
if (YOUTUBE_RTMP_URL == null || YOUTUBE_RTMP_STREAM_KEY == null) {
Log.e("VideoSDK", "RTMP url or stream key missing.")
return@launch
}
val outputs: MutableList<LivestreamOutput> = ArrayList()
outputs.add(LivestreamOutput(YOUTUBE_RTMP_URL, YOUTUBE_RTMP_STREAM_KEY))

meeting!!.startLivestream(outputs, null)
} else {
meeting!!.stopLivestream()
}
} catch (e: VideoSDKException) {
Log.e("VideoSDK", "Livestream request failed: ${e.code} ${e.name}")
}
}
}

Events​

  • onLivestreamStateChanged - An onLivestreamStateChanged event will be triggered any time the broadcasting state of a meeting changes. startLivestream() returns once the request is sent, so wait for LIVESTREAM_STARTED before you show that the meeting is live.
object : MeetingEventListener() {
override fun onLivestreamStateChanged(livestreamState: String) {
when (livestreamState) {
"LIVESTREAM_STARTING" -> Log.d( "LivestreamStateChanged",
"Meeting livestream is starting"
)
"LIVESTREAM_STARTED" -> {
livestreaming = true
Log.d("LivestreamStateChanged", "Meeting livestream is started")
}
"LIVESTREAM_STOPPING" -> Log.d("LivestreamStateChanged",
"Meeting livestream is stopping"
)
"LIVESTREAM_STOPPED" -> {
livestreaming = false
Log.d("LivestreamStateChanged", "Meeting livestream is stopped")
}
}
}

}

Got a Question? Ask us on discord