Skip to content

Commit

Permalink
Fix rendering video in sample iOS app
Browse files Browse the repository at this point in the history
  • Loading branch information
shepeliev committed Sep 18, 2024
1 parent b2a0d9f commit 58d7cfe
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
21 changes: 17 additions & 4 deletions sample/composeApp/src/commonMain/kotlin/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,30 @@ fun App() {
Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
val localVideoTrack = localStream?.videoTracks?.firstOrNull()

localVideoTrack?.let { Video(videoTrack = it, modifier = Modifier.weight(1f)) }
?: Box(modifier = Modifier.weight(1f))
localVideoTrack?.let {
Video(
videoTrack = it,
modifier = Modifier.weight(1f).fillMaxWidth()
)
} ?: Box(
modifier = Modifier.weight(1f).fillMaxWidth(),
contentAlignment = Alignment.Center,
) {
Text("Local video")
}

remoteVideoTrack?.let {
Video(
videoTrack = it,
audioTrack = remoteAudioTrack,
modifier = Modifier.weight(1f),
modifier = Modifier.weight(1f).fillMaxWidth(),
)
} ?: Box(
modifier = Modifier.weight(1f).fillMaxWidth(),
contentAlignment = Alignment.Center,
) {
Text("Remote video")
}
?: Box(modifier = Modifier.weight(1f))

Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
if (localStream == null) {
Expand Down
3 changes: 2 additions & 1 deletion sample/composeApp/src/iosMain/kotlin/Video.ios.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ actual fun Video(videoTrack: VideoStreamTrack, modifier: Modifier, audioTrack: A
UIKitView(
factory = {
RTCMTLVideoView().apply {
contentMode = UIViewContentMode.UIViewContentModeScaleAspectFit
videoContentMode = UIViewContentMode.UIViewContentModeScaleAspectFit
videoTrack.addRenderer(this)
}
},
modifier = modifier,
onRelease = { videoTrack.removeRenderer(it) }
)
}
3 changes: 0 additions & 3 deletions sample/iosApp/iosApp/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,3 @@ struct ContentView: View {
.ignoresSafeArea(.keyboard) // Compose has own keyboard handler
}
}



0 comments on commit 58d7cfe

Please sign in to comment.