user5278889
user5278889

Reputation:

Swift VLCKit VLCMediaPlayer frame not laying out correctly

I am trying to play an RTSP live stream using VLCKit. Everything works except when the video starts playing, it's not bounding to the entire view's frame. If I resize my window, then it does update, but I am not sure what I am doing wrong on the view initiation.

I've attached my code, as well as what the video looks like before and after resizing the window.

class VLCPlayerNSView: NSView {
    private var player: VLCMediaPlayer!

    init(player: VLCMediaPlayer) {
        super.init(frame: .zero)
        self.player = player
        self.player.drawable = self
        self.player.play()
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}

enter image description here

enter image description here

Upvotes: 2

Views: 1357

Answers (2)

Danila Plee
Danila Plee

Reputation: 748

UPDATE 10.12.2022:

IN VLCKit 3.5.0 this problem is no more

OLD:

ok after a lot of experimenting i realised this is related to the initial video quality size of the source so if you are running a 720p on a mac it will scale by default to a resolution of 640x360 because of retina. I was able to fix it by manually resizing the window a few times like this after the video starts:


  func autoScaleVideo() {
    let incr = 5.0
    self.playerWindow.setFrame(NSRect(x: self.playerWindow.frame.origin.x, y: self.playerWindow.frame.origin.y, width: self.playerWindow.frame.width+incr, height: self.playerWindow.frame.height+incr), display: true)
    self.playerWindow.setFrame(NSRect(x: self.playerWindow.frame.origin.x, y: self.playerWindow.frame.origin.y, width: self.playerWindow.frame.width-incr, height: self.playerWindow.frame.height-incr), display: true)
  }

and also setting the window aspect size is important


    let aspectWidth = 640.0
    let aspectHeight = 360.0
    self.playerWindow.aspectRatio = .init(width: aspectWidth, height: aspectHeight)
    self.vlcMediaPlayer.scaleFactor = 0;

this is not a good solution but it works most of the time, someone from vlc should offer a better one, but whatever the original vlc app downscales the window each time to the video size when you open a new video, so I have no idea if there is any solution from vlc.

Upvotes: 0

mfkl
mfkl

Reputation: 2184

super.init(frame: .zero)

This looks wrong. Try giving it a positive value.

Upvotes: -1

Related Questions