I am trying to implement AvPlayer in compose here ...
# compose-ios
a
I am trying to implement AvPlayer in compose here is my Code
@Composable
actual fun Player(modifier: Modifier, url: String) {
_Box_(modifier = modifier) *{*
val player = _remember_ *{*
AVPlayer()
}
_UIKitView_(
modifier = Modifier.
_fillMaxSize_(),
factory =
{
val playerView = UIView()
val playerLayer = AVPlayerLayer() playerLayer.setPlayer(player) playerLayer.setFrame(playerView.frame) playerLayer.videoGravity=
AVLayerVideoGravityResizeAspectFill
playerView.layer.addSublayer(playerLayer)
playerView
*}*,
)
_LaunchedEffect_(url) *{*
val asset = AVURLAsset(NSURL(string = url), null)
val playerItem = AVPlayerItem(asset = asset)
player._replaceCurrentItemWithPlayerItem_(
item = playerItem ) player.
_play_()
}
_DisposableEffect_(url) *{*
onDispose *{*
player._replaceCurrentItemWithPlayerItem_(null)
}
}
}
}
🧵 3
a
this may help. And please don't write message sequences and large code samples to the general chat. Use short message and provide additional info in the thread.
To be short, for now there is a bug in UIKItView and you should remember your factory lambda to prevent behaviour you faced with
a
@Alexander Zhirkevich thanks really helped me It's working know