mirror of
https://github.com/yattee/yattee.git
synced 2024-12-15 06:40:32 +05:30
52 lines
1.2 KiB
Swift
52 lines
1.2 KiB
Swift
import AVFoundation
|
|
import Foundation
|
|
#if os(macOS)
|
|
import AppKit
|
|
#else
|
|
import UIKit
|
|
#endif
|
|
|
|
#if os(macOS)
|
|
final class PlayerLayerView: NSView {
|
|
var player: PlayerModel! { didSet {
|
|
wantsLayer = true
|
|
}}
|
|
|
|
override init(frame frameRect: NSRect) {
|
|
super.init(frame: frameRect)
|
|
}
|
|
|
|
override func makeBackingLayer() -> CALayer {
|
|
player.avPlayerBackend.playerLayer
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
super.init(coder: coder)
|
|
}
|
|
}
|
|
#else
|
|
final class PlayerLayerView: UIView {
|
|
var player: PlayerModel!
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
}
|
|
|
|
private var layerAdded = false
|
|
|
|
@available(*, unavailable)
|
|
required init?(coder _: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
override func layoutSubviews() {
|
|
if !layerAdded {
|
|
layerAdded = true
|
|
layer.addSublayer(player.avPlayerBackend.playerLayer)
|
|
}
|
|
player.avPlayerBackend.playerLayer.frame = bounds
|
|
super.layoutSubviews()
|
|
}
|
|
}
|
|
#endif
|