Mac OSX swift resize video view

484 views Asked by At

I need to display a video in my app, and would like to be able to resize it.

On a button, i have a Modal Segue.

The code of the view is :

import Cocoa
import AVKit
import AVFoundation
import MediaPlayer
class NSViewController2: NSViewController {

    let controller=AVPlayerView()    
    override func viewDidLoad() {
        super.viewDidLoad()

        let player = AVPlayer(url: v2!)
        controller.player=player
        controller.frame = self.view.frame

        self.view.addSubview(controller)
        player.play()

    }
}

The video starts fine and is displayed, but when i resize the modal windows, the video is not resized ..

Any idea ?

Thanks, Nicolas

1

There are 1 answers

0
n savoini On

If anyone is wondering ..

import Cocoa
import AVKit
import AVFoundation
import MediaPlayer

class competitionVideoViewController: NSViewController , NSWindowDelegate {

    let controller=AVPlayerView()

    override func viewDidLoad() {
        super.viewDidLoad()
        if ( competitionSelected >= 0 && competitions[competitionSelected].video != nil ) {
            let player = AVPlayer(url: competitions[competitionSelected].video! )
            controller.player=player
            controller.frame = self.view.frame
            self.view.addSubview(controller)
            player.play()
        }
    }

    func windowDidResize(_ notification: Notification) {
        controller.frame = self.view.frame
    }

}

1/ Add the NSWindowDelegate, in the class

2/ Add the function "windowDidResize"