yattee/Shared/Player/PlayerLayerView.swift
2022-10-27 18:03:57 +02:00

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: CGRect) {
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