2

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

DevelUpGames
  • 139
  • 1
  • 14
  • Maybe it has something to do with the fact that you are initializing the frame with .zero? – Bharat Jan 13 '21 at 18:17
  • I have a similar problem since upgrading VLCKit, but in ObjC - did you find a solution, or did the answer below work? – davidb Jun 27 '21 at 11:18

2 Answers2

0

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.

Danila Plee
  • 698
  • 5
  • 5
-1
super.init(frame: .zero)

This looks wrong. Try giving it a positive value.

mfkl
  • 1,914
  • 1
  • 11
  • 21