Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IOS] UIKitView RTCMTLVideoView Layout Bug #144

Open
JackyYangPassion opened this issue Oct 15, 2024 · 0 comments
Open

[IOS] UIKitView RTCMTLVideoView Layout Bug #144

JackyYangPassion opened this issue Oct 15, 2024 · 0 comments

Comments

@JackyYangPassion
Copy link

JackyYangPassion commented Oct 15, 2024

BUG Question

RTCMTLVideoView can't be filled with UIKitView components or Box components

RTCMTLVideoView should be filled with UIKitView components, that is, the length and height should be the same

Box(
    modifier = modifier.fillMaxWidth().aspectRatio(16f/9f)
      .clickable(
        interactionSource = interactionSource,
        indication = null,
        onClick = {
        }
      ),
    contentAlignment = Alignment.Center
  ) {
    remoteVideoTrack?.let {
        Box(modifier = Modifier.matchParentSize().onGloballyPositioned { layoutCoordinates ->
          val width = layoutCoordinates.size.width
          val height = layoutCoordinates.size.height
          log.v{ "remoteVideoTrack Width: $width, Height: $height" }
        }) {
          Video(
            videoTrack = it,
            audioTrack = remoteAudioTrack,
            modifier = Modifier.fillMaxSize().onGloballyPositioned { layoutCoordinates ->
              val width = layoutCoordinates.size.width
              val height = layoutCoordinates.size.height
              log.v{ "Video Width: $width, Height: $height" }}
          )
        }
    }?: Box(modifier = Modifier.matchParentSize().background(Color.Black).onGloballyPositioned { layoutCoordinates ->
      val width = layoutCoordinates.size.width
      val height = layoutCoordinates.size.height
      log.v{ "Init Box Width: $width, Height: $height" }
    }) {
      
   }
  }



@OptIn(ExperimentalForeignApi::class)
@Composable
actual fun Video(videoTrack: VideoStreamTrack, modifier: Modifier, audioTrack: AudioStreamTrack?) {
    UIKitView(
        factory = {
            RTCMTLVideoView().apply {
                videoContentMode = UIViewContentMode.UIViewContentModeScaleToFill
                videoTrack.addRenderer(this)
            }
        },
        modifier = modifier,
        onRelease = { videoTrack.removeRenderer(it) }
    )
}

Situation 1: This manual setting can fill the entire parent view, but intercepts the captured video content.


NSLayoutConstraint.activateConstraints(listOf(
  widthAnchor.constraintEqualToConstant(1290.toDp().value.toDouble()),  // 设置宽度
  heightAnchor.constraintEqualToConstant(726.toDp().value.toDouble())  // 设置高度
))

Situation 2: The actual operating effect is that there is a blank space and the Box is not filled as expected.

UIKitView(
    factory = {
      RTCMTLVideoView().apply {
        translatesAutoresizingMaskIntoConstraints = false
        videoContentMode = UIViewContentMode.UIViewContentModeScaleToFill
        videoTrack.addRenderer(this)

        
        dispatch_async(dispatch_get_main_queue()) {
          if (superview != null) {
            log.v("superview is not null")
            NSLayoutConstraint.activateConstraints(listOf(
              leadingAnchor.constraintEqualToAnchor(superview!!.leadingAnchor),
              trailingAnchor.constraintEqualToAnchor(superview!!.trailingAnchor),
              topAnchor.constraintEqualToAnchor(superview!!.topAnchor),
              bottomAnchor.constraintEqualToAnchor(superview!!.bottomAnchor)
            ))
          } else {
            log.v("superview is null")
          }
        }
      }
    },
    modifier = modifier,
    onRelease = { videoTrack.removeRenderer(it) }
  )

Can you help me modify the above logic to make it adaptive and fill the parent view?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant