Reputation: 552
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
Upvotes: 1
Views: 493
Reputation: 552
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"
Upvotes: 2