cxfksword / MPVKit

mpv library for iOS, macOS, tvOS applications
GNU General Public License v3.0
71 stars 19 forks source link

Player won't resize on iOS when using Metal #17

Open funniray opened 3 months ago

funniray commented 3 months ago

Hey there,

I've been playing with the demo projects provided, but I don't seem to be able to get MPV to detect the metal layer resizing... I've added the following to MPVMetalViewController

    override func viewDidLayoutSubviews() {
        let size = view.frame.size
        let scale = UIScreen.main.nativeScale

        metalLayer.frame = view.frame
        metalLayer.drawableSize = CGSize(width: size.width * scale, height: size.height * scale)
    }

I can see with the performance overlay that the metal layer has resized, however, the video content isn't modified.

Is there any way to get resizing to work with libmpv on iOS?

alexiscn commented 3 months ago

try following code

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()

        metalLayer.frame = view.bounds
        metalLayer.contentsGravity = .resizeAspect
    }
funniray commented 3 months ago

@alexiscn

The code did work and the view does fill the screen, however the metal layer's resolution never changed. I would prefer the resolution of the metal layer to be correct so that subtitles are rendered properly.

You can see in the clip below that the resolution of the metal layer never changed

https://github.com/cxfksword/MPVKit/assets/16416198/0123c438-3ca0-428b-b845-d6507809e04b

alexiscn commented 3 months ago

You may have a look the plex fix the sizing issue on moltenvk . It seems they have a solution to fix the problem. But I could not make it work.

funniray commented 3 months ago

After quite a bit of trial and error -- and trying the plex fork of mpv -- I don't believe it's currently possible. It doesn't seem like anything that Plex has published so far has had fully working moltenvk resizing... I've tried multiple commits, but nothing appears to work :/