Mac OSX swift调整视频大小

时间:2016-12-16 22:48:26

标签: swift nsview avplayerview

我需要在我的应用中显示视频,并希望能够调整其大小。

在一个按钮上,我有一个模态瞄准。

视图的代码是:

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()

    }
}

视频开始正​​常并显示,但是当我调整模态窗口时,视频不会调整大小..

有什么想法吗?

谢谢, 尼古拉斯

1 个答案:

答案 0 :(得分:2)

如果有人想知道..

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 /在类

中添加NSWindowDelegate

2 /添加函数“windowDidResize”