mirror of
https://github.com/yattee/yattee.git
synced 2024-12-13 05:40:32 +05:30
37 lines
813 B
Swift
37 lines
813 B
Swift
import AVKit
|
|
import SwiftUI
|
|
|
|
final class PlayerViewController: NSViewController {
|
|
var video: Video!
|
|
|
|
var player = AVPlayer()
|
|
var playerState: PlayerState! = PlayerState()
|
|
var playerView = AVPlayerView()
|
|
|
|
override func viewDidDisappear() {
|
|
playerView.player?.replaceCurrentItem(with: nil)
|
|
playerView.player = nil
|
|
|
|
playerState.player = nil
|
|
playerState = nil
|
|
|
|
super.viewDidDisappear()
|
|
}
|
|
|
|
override func loadView() {
|
|
guard playerState.player == nil else {
|
|
return
|
|
}
|
|
|
|
playerState.player = player
|
|
playerView.player = playerState.player
|
|
|
|
playerView.controlsStyle = .floating
|
|
playerView.showsFullScreenToggleButton = true
|
|
|
|
view = playerView
|
|
|
|
playerState.loadVideo(video)
|
|
}
|
|
}
|