fix(ios): fit the picture to the window after a rotation

MPVKit's MoltenVK context reads the layer's drawableSize only when mpv
builds its video output and reports no resize after that (mpvkit/MPVKit#3).
A player opened upright and turned on its side went on drawing the upright
frame into a corner of the landscape drawable. The view now tells the
player when its drawable changes, and once the size settles the player
rebuilds mpv's output by turning the picture off and on, as the background
already does. The vid writes run in order off the main thread.
This commit is contained in:
nvrl committed 2026-10-14 18:01:22 +02:00
1 parent cafd969567
commit 8d615579e2
2 files changed
+60 -4

No files matched your search

+7 -3
View File
@@ -724,16 +724,18 @@ struct MpvView: UIViewRepresentable {
let player: MpvPlayer
func makeUIView(context _: Context) -> LayerView {
LayerView(layer: player.layer)
LayerView(player: player)
}
func updateUIView(_: LayerView, context _: Context) {}
final class LayerView: UIView {
private let player: MpvPlayer
private let video: CAMetalLayer
init(layer video: CAMetalLayer) {
self.video = video
init(player: MpvPlayer) {
self.player = player
video = player.layer
super.init(frame: .zero)
backgroundColor = .black
video.removeFromSuperlayer()
@@ -759,6 +761,8 @@ struct MpvView: UIViewRepresentable {
video.contentsScale = scale
video.drawableSize = CGSize(width: bounds.width * scale, height: bounds.height * scale)
CATransaction.commit()
// A new drawable is not enough on its own: mpv has to be told.
player.outputResized()
}
override func didMoveToWindow() {