```@Composable actual fun VideoPlayer(modifier: Mo...
# compose-ios
j
Copy code
@Composable
actual fun VideoPlayer(modifier: Modifier, url: String) {
    val player = remember { AVPlayer(uRL = NSURL.URLWithString(url)!!) }
    val playerLayer = remember { AVPlayerLayer() }
    val avPlayerViewController = remember { AVPlayerViewController() }
    avPlayerViewController.player = player
    avPlayerViewController.showsPlaybackControls = true

    playerLayer.player = player
    playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
    UIKitView(
        factory = {
            // Create a UIView to hold the AVPlayerLayer
            val playerContainer = UIView()
            playerContainer.addSubview(avPlayerViewController.view)
            playerContainer
        },
        onResize = { view: UIView, rect: CValue<CGRect> ->
            CATransaction.begin()
            CATransaction.setValue(true, kCATransactionDisableActions)
            view.layer.setFrame(rect)
            playerLayer.setFrame(rect)
            avPlayerViewController.view.layer.frame = rect
            CATransaction.commit()
        },
        update = {
            player.play()
            avPlayerViewController.player?.play()
        },
        modifier = modifier
    )
}
What am I missing to make this Composable to resize video to fit the size of the Composable? At the moment its using its constraints and keep aspect ratio of video. I want to it stretch video layer to expand and crop/fit the video layer inside the Composable.
a
So I just implemented something to grab the video's dimensions/aspect ratio and then resize the container around the video player. Would that help you?
👍 1
j
I solved it. Container had correct size, issue was that both player view controller and player layer needed same properties for video gravity to zoom the video and fit into container.