Slide 101
Slide 101 text
● Playerインスタンスの生成 + 動画再生画面の描画 for iOS
動画を表示する(2/2)
101
3. 画像・動画の表示
@Composable
actual fun VideoPlayer(
url: Uri,
modifier: Modifier,
) {
val nsUrl = NSURL.URLWithString(url.value) ?: return
val player = remember { AVPlayer(uRL = nsUrl) }
val playerViewController = remember { AVPlayerViewController() }
playerViewController.player = player
playerViewController.showsPlaybackControls = true
UIKitView(
factory = { playerViewController.view },
update = { player.play() },
onResize = { view: UIView, rect: CValue ->
CATransaction.begin()
CATransaction.setValue(true, kCATransactionDisableActions)
view.layer.frame = rect
CATransaction.commit()
},
modifier = modifier,
)
}
iosMain/VideoPlayer.kt
UIKitView(
factory = { playerViewController.view },
update = { player.play() },
onResize = { view: UIView, rect: CValue ->
/* Viewのサイズ調整 */
},
modifier = modifier,
)