Joel Denke
01/18/2024, 11:02 AM@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.Andrew Watson
01/19/2024, 11:43 PMJoel Denke
01/20/2024, 8:33 AM