1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 22:00:31 +05:30
yattee/Shared/Player/PlayerLayerView.swift

52 lines
1.2 KiB
Swift
Raw Normal View History

2022-05-21 02:53:14 +05:30
import AVFoundation
import Foundation
2022-08-19 04:10:46 +05:30
#if os(macOS)
import AppKit
#else
import UIKit
#endif
2022-05-21 02:53:14 +05:30
2022-08-19 04:10:46 +05:30
#if os(macOS)
final class PlayerLayerView: NSView {
var player: PlayerModel! { didSet {
wantsLayer = true
}}
2022-05-21 02:53:14 +05:30
2022-08-19 04:10:46 +05:30
override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
}
2022-05-21 02:53:14 +05:30
2022-08-19 04:10:46 +05:30
override func makeBackingLayer() -> CALayer {
player.avPlayerBackend.playerLayer
}
2022-05-21 02:53:14 +05:30
2022-08-19 04:10:46 +05:30
required init?(coder: NSCoder) {
super.init(coder: coder)
}
2022-05-21 02:53:14 +05:30
}
2022-08-19 04:10:46 +05:30
#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")
}
2022-05-21 02:53:14 +05:30
2022-08-19 04:10:46 +05:30
override func layoutSubviews() {
if !layerAdded {
layerAdded = true
layer.addSublayer(player.avPlayerBackend.playerLayer)
}
player.avPlayerBackend.playerLayer.frame = bounds
super.layoutSubviews()
}
2022-05-21 02:53:14 +05:30
}
2022-08-19 04:10:46 +05:30
#endif