Kotlin

Connect, Publish and Show Yourself

After permissions are granted:

  1. Build a Session with App ID and session ID.
  2. connect(token).
  3. In onConnected, build a Publisher, attach publisher.view to a container, then session.publish(publisher).
val session = Session.Builder(context, VideoConfig.APP_ID, VideoConfig.SESSION_ID)
    .build()

session.setSessionListener(object : Session.SessionListener {
    override fun onConnected(session: Session) {
        val publisher = Publisher.Builder(context).build().apply {
            setPublisherListener(/* … */)
            setStyle(
                com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_SCALE,
                com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_FILL
            )
        }
        publisherContainer.removeAllViews()
        publisherContainer.addView(publisher.view)
        session.publish(publisher)
    }

    override fun onDisconnected(session: Session) {}
    override fun onError(session: Session, error: com.opentok.android.OpentokError) {}
    override fun onStreamReceived(session: Session, stream: Stream) { /* Step 5 */ }
    override fun onStreamDropped(session: Session, stream: Stream) { /* Step 5 */ }
})

session.connect(VideoConfig.TOKEN)

Call session.onResume() / session.onPause() from the hosting Activity or Fragment to match app lifecycle.

Simple Multiparty

Learn how to use the Vonage Android SDK for a multi-party call. The application publishes audio/video from a device and can connect to multiple subscribers.

Available on:
Kotlin
Steps
1
Introduction
2
Getting Started
3
Creating a new project
4
Adding the Android SDK
5
Setting up authentication
6
Requesting permissions
7
Connect publish and show yourself
8
Multiparty subscribe to every remote stream
9
Host SDK views in AndroidView
10
Running the app
11
Conclusion