//
//  ZZHExternalViewController.swift
//  SwiftProject
//
//  Created by aaa on 2024/3/27.
//

import Foundation
import UIKit
import AVKit

class ZZHExternalViewController: UIViewController {
    
    var imageView: UIImageView?
    var playerLayer:AVPlayerLayer?
    override func viewDidLoad() {
        super.viewDidLoad()
        print("ZZHExternalViewController viewDidLoad..")
        imageView = UIImageView()
        imageView?.image = UIImage(named: "loading")
        imageView?.contentMode = .scaleAspectFit
        self.view .addSubview(imageView!)
        imageView?.snp.makeConstraints({ make in
            make.left.top.right.bottom.equalTo(0)
        })
//        imageView?.transform = CGAffineTransform(rotationAngle: -.pi / 2)
        
        
        playerLayer = AVPlayerLayer()
        if let externalScreen = UIScreen.screens.first(where: { $0 != UIScreen.main }) {
            let externalScreenSize = externalScreen.bounds.size
            playerLayer!.frame = CGRectMake(-externalScreenSize.width*0.5, -externalScreenSize.height*0.5, externalScreenSize.width*2, externalScreenSize.height*2)
            print("外接屏幕的尺寸是: \(externalScreenSize)")
        } else {
            print("没有发现外接屏幕")
        }
        self.view.layer.addSublayer(playerLayer!)
        self.view.backgroundColor = .orange
    }
    
    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        
        print("bounds:\(self.view.bounds)")
        print("frames:\(playerLayer!.frame)")
    }
}
