Kotlin

Adjusting the sample app UI

The Android SDK exposes the video streams (both published and subscribed) as View objects. You can attach these views to any composable view in your layout.

  1. Create a composable view

In Android Studio:

  • Create a new file VideoChatScreen.kt
  • Fill contents of the file with:
@Composable
fun VideoChatScreen(
    publisherView: View?,
    subscriberView: View?
) {
    Box(modifier = Modifier.fillMaxSize()) {

        // Subscriber full-screen
        subscriberView?.let { view ->
            AndroidView(
                factory = { view },
                modifier = Modifier
                    .fillMaxSize()
            )
        }?: run {
            Text(
                "Connect another subscriber to this session to see his/hers video",
                modifier = Modifier
                .fillMaxSize()
                    .padding(vertical =
                    150.dp)
            )
        }


        publisherView?.let { view ->
            // Publisher picture-in-picture
            AndroidView(
                factory = { view },
                modifier = Modifier
                    .size(width = 90.dp, height = 120.dp)
                    .align(Alignment.BottomEnd)
                    .padding(16.dp)
                    .background(Color.LightGray)
            )
        }
    }
}
  1. Now declare publisherView and subscriberView as properties of the MainActivity class (right after the declaration for the session property):
private var publisherView by mutableStateOf<View?>(null)
private var subscriberView by mutableStateOf<View?>(null)
  1. Finally, in the existing onCreate() method, initialize the VideoChatScreen view by adding it via the setContent() method call:
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    enableEdgeToEdge()

    setContent {
        VideoChatScreen(
            publisherView = publisherView,
            subscriberView = subscriberView
        )
    }

    requestPermissions()
}