         }
         playerView.player = player
         
+        kvoController.observe(player, keyPath: #keyPath(AVPlayer.currentItem.presentationSize), options: [.initial, .new], action: #selector(setupWindowSizing))
+        
         player?.currentItem?.asset.loadValuesAsynchronously(forKeys: ["tracks"]) { [weak self] in
             DispatchQueue.main.async {
-                self?.setupWindowSizing()
                 self?.setupTimeObserver()
                 
                 if let session = self?.session {

        } as AnyObject?
    }
    
    func setupWindowSizing()
    {
        if let asset = player?.currentItem?.asset {
            // get video dimensions and set window aspect ratio
            let tracks = asset.tracks(withMediaType: AVMediaTypeVideo)
            if tracks.count > 0 {
                let track = tracks[0]
                videoNaturalSize = track.naturalSize
                playerWindow.aspectRatio = videoNaturalSize
            } else {
                return
            }
        } else {
            return
        }
        
        // get saved scale
        let lastScale = Preferences.SharedPreferences().lastVideoWindowScale

    // resizes the window so the video fills the entire screen without cropping
    @IBAction func sizeWindowToFill(_ sender: AnyObject?)
    {
        guard aspectRatioSet else { return }
        
        Preferences.SharedPreferences().lastVideoWindowScale = 100.0
        
